Right, so I am looking for a way to get Euler rotation angles, but in a different rotation order. Unity calculates the rotation values as Z * X * Y. How would I convert this to X * Y * Z, or any other variant? Any examples or info in the right direction would be much appreciated. Thanks!
I’m sure there is a mathematical transform but I don’t know it without googling.
However, if you are looking to get a particular rotational behavior other than the default Unity way of applying axes rotation, I recommend instead that you use separate game objects parented to one another to achieve the results you want.
The Hierarchy for such a thing would look like:
Root
PivotX
PivotY
PivotZ
TheObjectThatPivots
The takeaway here is that you can rearrange the parenting to get whatever type of behavior you want. Each game object would ONLY rotate in a single axis. It makes the problem very easy to understand and digest.
If you’re doing this in script, you can use Quaternion.AngleAxis for each axis, along with the * operator (which combines Quaternions).
This sample code does its thing one step at a time so it can use its previous rotation to affect the axis it’s now rotating on.
Quaternion newRotation = Quaternion.AngleAxis(xAngle, Vector3.right);
newRotation *= Quaternion.AngleAxis(yAngle, newRotation * Vector3.up);
newRotation *= Quaternion.AngleAxis(zAngle, newRotation * Vector3.forward);