I have a teleport-like object that changes the player’s position and direction facing, but I can’t seem to eliminate the player’s velocity/momentum on arrival (because of the new positioning, if the player ran fast enough into the teleporter, the momentum will carry him backward into a return teleport). I’ve tried setting
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
during the relocation, but these seem to have no effect on the momentum of the player whatsoever. I pretty much don’t know anything about physics handling or Rigidbody, so maybe I’m misunderstanding how these work. Any suggestions?
2 Answers
2Maybe you should try setting rigidbody.angularVelocity and rigidbody.velocity to 0 before arrival?
Setting rigidbody.velocity works. But it does not stop any other forces that are being applied. It just counteracts any velocity that has build up to the point you set the velocity to 0. For example, if gravity is turned on or you are applying a constant force, the object will just accelerate again.
One solution is to not only set the Rigidbody.velocity but to also set the Rigidbody.isKinematic to true. Then you can set it back to false when you want it to have the object become active again.
If you are not applying any forces after the relocation, then add some Debug.Log() statements to verify that 1) the velocity is getting set to 0, and 2) output the velocity to see if there is not a force you have not considered being applied.