Make a rigidbody sphere stop while moving fast

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!

2 Answers

2

rigidbody.velocity = Vector3.zero;
//and if you want it to stop spinning too
rigidbody.angularVelocity = 0;

Thank you so much! Works like a charm, though I had to change the 2nd line: rigidbody.angularVelocity = Vector3.zero;

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.