Confused by eulerAngles

I’m really confused by these eulerAngles.

For example, if you tilt the X one wa by 10 degrees, the tilt is 10 degrees. If you tilt it the other way by 10 degrees, it is 350 degrees. I get that it’s 360-10, but then this code confuses me.
if(tiltInX < standingThreshold && tiltInZ < standingThreshold)
return true;
if tiltInX is less than standing threshold, then it is standing up.
So if threshold is 20, and you tilt X forward by 10, then this code wont run, and the pin is standing up. And if you do tilt a pin forwards by 10 degrees and run the game, gravity will pull it back to 0, because it isn’t tilted far enough to fall over.
Now, if you tilt X backwards, it is now 350 degrees, which is greater than standing threshold, so it should return false, however, the pin is still standing, because it won’t fall over with only a 10 degree tilt.
The same applies for Z. A 10 degree tilt in either or both directions won’t knock the pin down, but this code will say the pin is no longer standing if the tilt for x and z go to 350.

Hi Stephen,
In the Bowlmaster code, you should be taking the absolute value of x and y, using Mathf.Abs().
The absolute value is the magnitude of the number, so ignores the sign.

With you’re X/Z rotation at 0 (not 360), you get 0+10=10 and 0-10 = -10. However, since you’re just looking at the magnitude of the number, the answer is 10 in both cases.

This is why the code work, even though you’re only checking it against a single value for the standing threshold.

I hope that clarifies it for you.

Thanks for your reply, but I’m still a little confused.
When the X/Z was rotated backwards, the number was printing to the console was 350.
So when Mathf.Abs gets the absolute value, isn’t it getting 350?

Were you printing the same line of code to the console, or were you using a different method to show the rotation in the console?

In my experience you can’t really trust the values that Unity shows you for rotation, since it actually uses quaternions for calculation but never shows them to you. Instead it shows you the Euler angles, since they are more human readable. However sometimes things can get a little lost in translation between the two.

haha so it’s not just me, it’s Unity being awkward?
I was printing the same line that Ben was, I seen his show something like 350 too at one point.
I’ll remember that. Thanks for your help :slight_smile:

Privacy & Terms