According to the documentation, with Euler angles:
rotations are performed around the Z axis, the X axis, and the Y axis, in that order.
When I try to reproduce it in the inspector and with scripts, it seems that the rotation order is “YXZ”, and not “ZXY”.
Do you know the reason of this behaviour ? If Unity use the “YXZ” order, do you know how to convert the euler angles to “ZXY” ?
You can check the GIF files or the script below:
using UnityEngine;
public class RotationTest : MonoBehaviour
{
public Vector3 rotation;
public bool useYXZ = true;
private void Awake()
{
if (useYXZ) ApplyQuaternionYXZ();
else ApplyQuaternionZXY();
Debug.Log(transform.eulerAngles);
}
private void ApplyQuaternionYXZ()
{
transform.RotateAround(transform.position, transform.up, rotation.y);
transform.RotateAround(transform.position, transform.right, rotation.x);
transform.RotateAround(transform.position, transform.forward, rotation.z);
}
private void ApplyQuaternionZXY()
{
transform.RotateAround(transform.position, transform.forward, rotation.z);
transform.RotateAround(transform.position, transform.right, rotation.x);
transform.RotateAround(transform.position, transform.up, rotation.y);
}
}