I am trying to use the rotation values from a Unity gameobject in another program. But I can’t get the two to agree on rotations of all axes and at certain angles, the object in the other program flips over or backwards.
Here’s the inconsistency I am seeing:
INSPECTOR: x: -89 y: 0 z: -90 <|> PRINTS: x: 271 y: 0 z: 270
INSPECTOR: x: -90 y: 0 z: -90 <|> PRINTS: x: 270 y: 270 z: 0
INSPECTOR: x: -91 y: 0 z: -90 <|> PRINTS: x: 271 y: 180 z: 90
When I sweep the object from 0 to 180 and check in the external program, I see that at 90 degrees the object does some random flips. However if I enter the rotations manually exactly as displayed in the inspector, the external program works perfectly fine.
All I am doing is printing (and saving these values to a text file for the external program to use):
Vector3 eulerAngles = object.rotation.eulerAngles;
Debug.Log("transform.rotation angles x: " + eulerAngles.x + " y: " + eulerAngles.y + " z: " + eulerAngles.z);
I have even tried object.localEulerAngles and object.localRotation.eulerAngles but get the exact same inconsistency.
Why is there no way to get these values? I have been on Google for a very long time and nothing is explained. I need the inspector values or a way to trick Unity into producing the same numbers via other means.
Please help, my script is so close, I just can’t believe the inspector and the printed values differ by so much and there’s no way to get the values shown, that’s insane!!