I'm trying to rotate a piece by special conditional increments (ie. 30, then 90, then 150, then 180, then 210, then 270, then 360) on an arbitrary axis in global space. Sounds easy enough, by checking which of these your axis is at and then setting it to the next one. However, in global space, a rotation in one axis will often be translated as changes to the others to keep it showing the way you meant with Unity's Z,X,Y rotation application order. To see an example, try rotating something to 180 degrees in the Y axis, then try doing the same with the X axis to see how it only ever gets 90 degrees away from 0 before changing other axes and coming back down. There doesn't seem to be a difference between Transform.localEulerAngles and Transform.eulerAngles, both of which return the local ones. Thus, given all the possibilities for how a given global rotation can be represented in the local axis coordinates, is there a way to measure its "global rotation" of only one axis sanely?
(comments are locked)

Well, if you want a rotation about an arbitrary axis, you won't be able to check a single component against a value. Just make another property on the GameObject that stores the object's "current angle" (the 30, 90, 150, ... above) around your arbitrary axis, and have a way to get the "next angle" around that axis given whatever your current angle is. Then just use transform.RotateAround to rotate your object sensibly. For instance, when you're going from 30 degrees to 90 degrees:
Thanks. I considered doing that but wanted to make sure I wasn't being wasteful if there was an easier way to calculate a global angle from local Euler angles or directly from the Quaternion. I may end up having to store it statically like that though.
Mar 13 '12 at 03:17 PM
blitzen
(comments are locked)

Other than comparing it with objects that have known rotations, probably not. Using euler angles for this isn't a good idea, because the rotation itself isn't actually stored that way the euler angles are calculated from the Quaternion.
If I take the time to learn how quaternions work, will the global angle be easily readable directly, so I don't have to store them in a separate Vector3 as mentioned below?