- Home /
The question is answered, right answer was accepted
How not to lose speed when collided with wall?
my player is moving right and left , when collided with boundary (collider) it the opposite direction, i.e if its going in right direction then it will go left and vice versa. i have set a physics material to player and wall with zero friction and bounce.
my force formula is below
rb.AddRelativeForce (new Vector2 (speed, 0) - rb.velocity);
You can save the last velocity of your object, and when it collide your assign the last velocity in the otherway (something like rb.velocity = velocity *-1;)
using velocity, my 2d character is unable to jump using add forces
The idea is the same, You can just AddRelative force in the other way when you hit the wall, of the differene between the force you have before the hit and the force you have after
Answer by mansoor090 · Dec 07, 2018 at 08:37 AM
i Got the fix. using velocity i achieved the results.
rb.velocity = new Vector2 (speed, dir);
Answer by RohitNutalapati · Dec 06, 2018 at 04:36 PM
Try setting angular drag and drag to zero.
i added my answer below . check it out to prevent this problem in future