a variable that when an object is tilted 0º = 0 and 90º = 1

sounds simple, i know the math to do that. divide the rotation by 90 and you get it. anyway there is one problem with this: if the object tilts, for example, 15º on the x axis it would work, but if it tilts 15º in the oposite direction on the same axis the rotation will be something like 375º, and dividing this by 90 will certainly give me a number over 1. i need a way for it to give me a number between 0 and 1 regardless on the direction it tilts. and i certainly dont know how to do that math. ill keep on trying to achieve it but certainly a hand would be much apreciated. thanks to all.

p.s. if i was not clear on my explanation, which i probably wasnt, feel free to coment me or edit the post if u think there is a better way to explain it. thanks a lot for all your help, and happy new year.

I guess the easiest option is just checking if your rotation for a given axis is greater than 180 and in this case subtracting it from 360. C# sample for x axis:

float rotation = transform.eulerAngles.x;
if (rotation > 180f)
    rotation = 360f - rotation;
float tilt = rotation / 90f;

This sample will return values over 1 for rotation greater than 90 and lower than 270, but you can tune the sample to take this into consideration. Or if such angles are impossible in your case, then you can leave the sample as it is.

float magicNumber = (180-((angle+180)%360))/90;

Now this gives -1 to 1 (for -90 to +90) in case you also want to know the direction. If you don’t care about direction, slap a Mathf.Abs() around the formula.