- Home /
Easy way to remove all velocity
Hey guys,
a, hopefully, short and easy question this time. Ive been going thought the documentation on Rigidbody but I cannot seem to find an easy way to remove all velocity on a gameobject.
I've tried, of course, setting rigidbody.velocity to zero. This just seems to add zero to the current velocity though.
What I want is to respawn an object, which works, but I want all old velocity removed, how would I do this easily?
Edit for future reference:
Using rigidbody.velocity = Vector3.zero; does reset the velocity, but remember to also use rigidbody.angularVelocity = Vector3.zero to remove the spin.
Answer by Owen-Reynolds · Mar 31, 2011 at 04:32 PM
rigidbody.velocity=Vector3.zero
really does set automatic "physics" speed to nothing.
Something else must moving you. Maybe your script, for example, sets rigidbody.velocity=MySpd;
each frame. So, of course, reset MySpd
.
By Respawn, I assume you mean "teleport off left edge and pretend I'm a new car coming on"? If you are Instantiating (what I think of a a spawn,) there is no old velocity. It starts with the same stats as the prefab, which is always 0 for velocity.
You are right. When this object goes out of bounds I set it's transform to a 'respawnposition'. I've tried setting velocity to zero and I'm not manipulating it through script elsewhere, but I'll try it again. o.O maybe I did something wrong. Thanks for the help.
I think I figured it out. When I reset my object's transform and set it's velocity to zero it maintains it's current spin, causing it to move upon 'respawn'. Thanks for all the help.
Answer by efge · Mar 31, 2011 at 04:00 PM
You could "switch physics off":
rigidbody.isKinematic = true;
Thanks I'll try this. I was hoping for a solution that could be passed in one command from an external script. Because now I'll have to turn kinematic off in the next frame I guess?