- Home /
Question by
platinio2007 · Sep 23, 2019 at 11:30 PM ·
physicsrigidbodymath
How to calculate desire angular velocity?
Hi guys,
I want to rotate an object just using angular Velocity, so it can respond fine when collision to others objects, right now i am trying this.
Quaternion dRot = ( desireRotation) * Quaternion.Inverse( rb.rotation );
Vector3 dEuler = dRot.eulerAngles;
if (dEuler.x > 180) dEuler.x -= 360;
if (dEuler.y > 180) dEuler.y -= 360;
if (dEuler.z > 180) dEuler.z -= 360;
Vector3 w = dEuler / Time.fixedUnscaledDeltaTime;
Vector3 angularVelocity = ( w - rb.angularVelocity ) * 0.01f;
rb.angularVelocity = Vector3.MoveTowards( rb.angularVelocity, angularVelocity, angularVelocityChangeThreshold );
But it is no working, when it collides with others objects it start shaking and make strange movements, any idea what i am doing wrong?
Thanks in advance.
Comment
Answer by Hannibal_Leo · Sep 24, 2019 at 01:50 AM
You should use Quaternion.RotateTorwards to rotate an object at a fixed speed to your desired rotation and Rigidbody.MoveRotation to apply this rotation to the physic-engine.