- Home /
A way to kill rotation made by rigid body pysics?
I made a simple script that checks if the NPC has line of sight with the player when it enters a trigger and it works great my problem is that as soon as the NPC gets any kind of force applied to it it goes into an uncontrollable spin. Is there a way to stop this from happening aside from removing the rigid body?
First you can set angular drag to the object to keep it from spinning forever. You can also use constraints to restrict it's movement and rotation on each individual axis. In addition, you might want to also call rigidbody.maxAngularVelocity
on the object to keep angular velocity under check.
http://unity3d.com/support/documentation/ScriptReference/Rigidbody-maxAngularVelocity.html
http://unity3d.com/support/documentation/Components/class-Rigidbody.html
http://unity3d.com/support/documentation/ScriptReference/Rigidbody-angularDrag.html
Yeah I've already explored those, angulardrag does the job, but it also lowers the turn speed of my NPC, constraints stops my NPCs turning all together, maxangularvelocity doesnt slow down or stop the spin without also lowering the turn speed of my npc. In the shortest way i can say it is i want to put something in a function that arrests the spin imparted by physics forces. C# if i can get it :)
Answer by aldonaletto · Oct 14, 2011 at 11:07 PM
You can set rigidbody.freezeRotation to true. It's advisable when you use a rigidbody character, or a CharacterController with a rigidbody attached. This doesn't disallow rotations, only prevents physics from control them.
freezerotation worked similar to constraints and while i could toggle freeze to true and immediatly re-enable them (so my NPC doesnt fall on its face or side) but it doesnt actually stop it from spinning
transform.parent.rigidbody.constraints = RigidbodyConstraints.FreezeAll;
transform.parent.rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
If you just want to damp the angularVelocity, you try a brute force approach:
float damp = 0.9; // adjust the damp factor if necessary
void FixedUpdate(){ rigidbody.angularVelocity = rigidbody.angularVelocity * damp; ... }
Your answer
Follow this Question
Related Questions
Rotating a moving object 0 Answers
How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer
How can I convert velocity/direction to Force? 3 Answers
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Sum of multiple velocities 1 Answer