I have script that works with euler angles and it behaves differently on Windows PC and Android device.
I have the same Matrix4x4 as input but euler angles are not the same.
Test code:
var matrix = new Matrix4x4(
new Vector4(-1, 0, 0, 0),
new Vector4(0, 1, 0, 0),
new Vector4(0, 0, 1, 0),
new Vector4(0, 0, 0, 1)
);
var eulers = matrix.rotation.eulerAngles;
The contents of eulers on Windows device are (0, 180, -5.12263832E-05)
which I consider to be correct but on the Android device it's (309.394653, 318.791473, 256.987244)
.
Which obviously messes up my code. Do you have any idea how to "normalize" these results so that both eulers would be the same?
The matrix is returned by Tilemap.GetTransformMatrix(Vector3Int position)
and should represent orientation of a tile.
I figured out what I wanted to do as @jfd348 gave me a hint.
Your matrix is not a rotation matrix (in fact, it is a reflection about the YZ plane), so the very notion of Euler angles is not defined for it.
I used var quat = Quaternion.LookRotation(matrix.GetColumn(2), matrix.GetColumn(1));
to construct a quaternion that can be converted to eulers which represent correct rotation (or should i say orientation) on the 2D plane.