So like my question says, I was wondering if it’s possible to completely stop a rigidbody while it’s moving fast? I want the sphere in question to completely stop (speed = 0) when a button is pressed.
help preferably in C#.
Thanks!
So like my question says, I was wondering if it’s possible to completely stop a rigidbody while it’s moving fast? I want the sphere in question to completely stop (speed = 0) when a button is pressed.
help preferably in C#.
Thanks!
rigidbody.velocity = Vector3.zero;
//and if you want it to stop spinning too
rigidbody.angularVelocity = 0;
In general you should not modify directly a rigidbody’s velocity, because you override (break) the physic simulation. So to completely freeze an object, it seems more proper to just switch its bodyType to static.
yourRigidBody.bodyType = RigidbodyType2D.Static;
?? The manual page for velocity (https://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html) gives an example of when you should directly change it.
– Owen-Reynolds
Thank you so much! Works like a charm, though I had to change the 2nd line: rigidbody.angularVelocity = Vector3.zero;
– Renoki