# Get object rotation around the x axis

I have an object which can be rotated at 0, 90, 180, 270 degrees. I am using this to get the rotation data:

transform.eulerAngles.x


However that code keeps ignoring 180 degrees and instead shows 0 or some weird calculation which is basically zero (smth like -93+2323232-4)

I have read about quaternions, eulers and unity rotations in general and every time I curse my life when I have to work with unity rotations...

Is there any human readable and efficient/easy way to get the exact rotation the object has ? Or at least to get these values from 0 to 360.

Remember, Euler angles are a fiction, made for ease of data input in the scene editor. They're not stored under the hood, so when you read an Euler angle triplet, it's converted on the fly from the actual stored quaternion representation.

The quaternion will always give you consistent behaviour to calculate with - that's why we use them. The conversion from an orientation to Euler angles is arbitrary - many different Euler angle triplets correspond to the same orientation, and the engine has to pick wrap-around points somewhere, quite likely not where you want them.

So it's best to never use .eulerAngles as the input to a calculation. Treat this field as write-only. Never read with an aim to modify the value or make decisions based on the value, or you are extremely liable to make a mistake.

If you have an object that you only ever rotate around the x axis, you can compute its rotation about that axis by checking which direction its .forward vector is pointing:

float GetXDegrees(this Transform t) {
// Get the angle about the world x axis in range -pi to +pi,
// with 0 corresponding to a 180 degree rotation.

• If you want a Get_Rotation_X, you can add it as an extension method in three lines of code, as shown above, so it doesn't really need to be part of the standard API. Any users who want this can implement their own version that agrees with their own mental models, rather than standardizing one version that will necessarily chafe with somebody else's way of thinking. The inspector isn't doing anything magic, it's just holding a redundant copy of the Euler angles so it doesn't have to convert from quaternion between each edit - you can do the same in your own code if you want to pay that cost. Commented Jul 30, 2022 at 21:35