- Home /
Why does values of eulerAngles not match Rotate transform?
I have code where I'm rotating a part of an airplane like this:
rAileron.transform.Rotate(-5.0, 0.0, 0.0); print(rAileron.transform.eulerAngles.x);
and I get printed values like this:
278.6123 282.1982 286.5277 291.149
However, when I rotate the other way, +5, the eulerAngles.x values are still increasing like when I rotated -5:
rAileron.transform.Rotate(5.0, 0.0, 0.0); print(rAileron.transform.eulerAngles.x);
which prints:
278.6123 282.1981 286.5276 291.1488
What am I missing here? The part rotates correctly visually, but the values don't add up for me.
Answer by duck · Jan 06, 2010 at 10:41 PM
It could be because the Rotate function, as you're using it, rotates around the aileron GameObject's local X coordinate, but the eulerAngle values that you're reading out shows the rotation values relative to the world axes.
However, it's best to avoid using eulerAngles altogether wherever possible - and particularly the case of reading the euler values back out and expecting to do anything useful with them is a recipe for disaster!
Thanks. Good to know. If I have a realtime input that varies from 0 to 100 and I want my object to rotate through a corresponding range of 0 to 30 degrees, what's the best way to do the calculations and rotation?
Try this: transform.localRotation = Quaternion.Euler(input * 0.3, 0, 0);