- Home /
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!
Answer by The Kracken · Dec 07, 2013 at 01:24 AM
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;
Answer by Zooow · May 24, 2017 at 03:27 PM
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.
first line of the example: "In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour." So it depends on your "case" (ie. do you want/need to keep your physic simulation always coherent or not).
Your answer
Follow this Question
Related Questions
Grapple gun help 1 Answer
is it possible to make the player to transform into a differet object? 0 Answers
Equip in-game map item 1 Answer
spawn object on keypress c# 2 Answers
animation switch too fast 2 Answers