- Home /
Player is Speeding up in collisions
Hey there, I have a simple top down shooter Im working on.
Players can destroy the walls and then the debris will litter the level.
When the players run through the debris, they are speeding up. I don't know why this is happening.
I am using forces to move the players.
When I use ForceMode.VelocityChange, the players speed up when they are colliding with the level's debris:
Vector2 force = direction * movementForce * Time.deltaTime;
m_rigidBody.AddForce(force.x, 0.0f, force.y, ForceMode.VelocityChange);
When I Use ForceMode.Acceleration, the players slow down when they are colliding with the level's debris. Problem here is that they are slowing down way too much. To solve this, I changed the players rigid body mass to 2000 and the debris to 0,1. Player drag is 4, debris drag is 0.01.
I can't seem to find some values where the player just barely slows down when running through debris.
I think your problem is two fold here. You don't have enough code provided to give a full answer so I will request you post how you activate when the player hits debris, you might be accidentally applying it multiple times.
As for slowing down the Player, you're going to want a speed modifier that can adjust the final result of force before it is assigned. I'm working on a similar game but it doesn't use force, just a simple translation. So what you'll want is to do is modify the speed based on the type of object it is colliding with.
float step = (m_$$anonymous$$axSpeed * Time.deltaTime) * m_Speed$$anonymous$$odifier;
This is code from my game. So as you can see, the m_Speed$$anonymous$$odifier will effectively slow down the object when it walks on the debris. So you might have the m_Speed$$anonymous$$odifier = 0.25 or something when walking in debris, making the character walk at 1/4th the speed.
I am using rigid body forces and dont want to use a custom "speed modifier".
I think the Player is "speeding up" because his collision with the cube causes him to leave the ground, and then in the air he has no ground friction and moves quicker. I thiiink thats what's happening.
Ultimately I made it so the debris applies no force to the Player's rigid body, and the player just pushes them around with impunity. It's funner this way.
Your answer
Follow this Question
Related Questions
Rigid body child Player movement 0 Answers
Collisions causing Rigidbody to go Haywire and move randomly. 1 Answer
Issues Making Character Move With Rigidbody 1 Answer
A simple solution for constant rigidbody movement without changing and clamping velocity directly 2 Answers
Non slippery movement 1 Answer