- Home /
How to keep rotation from switching between - and + after a 360?
The title might be a bit vague, but I couldn't figure out how to explain with just a few words...
I have a vehicle that reacts to physics, and to rotate it, I apply torque to the axis I want. When I debug rigidbody.rotation.z, I get 0 to 1 when pitching up, and 0 to -1 when pitching down. But when I do a 360 flip, the rotation is now inverted, which means i get 0 to -1 when pitching up, and 0 to 1 when pitching down.
The problem is that I use the rotation values for certain things, eg:
if( rigidbody.rotation.z > 0.5f ) DoSomething();
Obviously when the rotation gets inverted after a 360 flip, that doesn't work the same anymore, so I did:
if( Mathf.Abs( rigidbody.rotation.z ) > 0.5f ) DoSomething();
Which works, but it seams that the addition of the Mathf.Abs calculation slows things down just enough the change when DoSomething() happens, making it inconsistant.
Is there any way to get around that problem? I would like the reset the rotation to Quaternion.Identity as soon as the vehicle did a complete 360 flip, but I can't figure out how to check for that, how can I tell when it went 360 degrees?
If anyone could give me a hint, or maybe a better way of doing what I'm doing, I'm all ears! Thanks for your time guys :)
Stephane