eulerAngles.x straight from 0° to 360°

Hi there,

I’m trying to get rotation.eulerAngles.x from an object, then make a calculation with it, then pass the result to another object.
Thus I really need to get rotation.eulerAngles.x straight from 0° to 360°.

But when I rotate the object on the x axis, rotation.eulerAngles.x goes from 0° to 90° on the first quarter, then from 90° to 0° on the second quarter, then from 360° to 270° on third quarter and finally from 270° to 360° on the last quarter.
This is probably due to Quaternion conversion as I read on other topics…

Do you know if there’s a way to get a value that goes straight from 0° to 360° out of the rotation.eulerAngles.x

Thanks !

I had to do something like this for vehicle movements and I used Mathf.atan2(y, x)*Mathf.Rad2Deg to calculate the angle. The only tricky part about this is determining how to get y and x. Since my vehicles were in 3D and rotating about the y axis, I used transform.forward.z and transform.forward.x like this:

var angle = Mathf.Atan2(transform.forward.z, transform.forward.x) * Mathf.Rad2Deg;

If you are doing something in 2D, you probably want to use y and x instead:

var angle = Mathf.Atan2(transform.forward.y, transform.forward.x) * Mtahf.Rad2Deg;

In other scenarios, like in 3D if something is rolling like a barrel or a wheel, you might use other things, so the exact axis chosen could vary. But this would get you a value from 0 to 360. I actually wanted -180 to 180, so at the end I threw in

if (angle > 180) angle -= 360;

to adjust my desired range.

Use: transform.localRotation.eulerAngles.x or y or z. This will give you a 0 to 360 range.

@molosev Please do not post comments as answers. Use the “Comment” button.