- Home /
How to know if an object has positive angularVelocity in LOCAL space
This is a follow up to the question here, which covered linear velocity. Is there a way, similar to InverseTransformDirection, that can turn angularVelocity in world space to angularVelocity in local space?
As in the previous post, I'm programming an automatic full stop feature for a spaceship, and I need to know whether the ship is moving in a positive or negative direction relative to its local axes -- if it's moving positive, then the full stop function applies negative AddRelativeForce, and vice versa, to bring the ship to a stop. For rotation, it's the same idea, except that I need to apply AddRelativeTorque. In other words, it's an inverse correlation: positive movement needs a negative force, negative movement needs a positive force.
The problem is that GetComponent().angularVelocity returns angular velocity in world space. So when the ship is turned around in world space (facing backwards or upside down, depending on which rotational axis we're talking about), the function doesn't work -- the inverse correlation breaks down. On the x axis for example (which controls whether the ship is pitching up or down), negative angular velocity in world space actually means positive pitch in local space, which needs to be countered by negative pitch. But because Unity sees negative angular velocity, it thinks that positive force is required to stop it -- which actually speeds up the pitch rotation, the opposite of what I need.
So, basically I'm looking for the rotational equivalent of InverseTransformDirection. (On a whim, I tried InverseTransformVector. Didn't work.)
Any help would be greatly appreciated.
Answer by theOtherHolmes · Jun 03, 2015 at 07:04 AM
After some deeper Googling, I think this is the answer: http://answers.unity3d.com/questions/17012/how-to-get-local-angularvelocity.html