Inspector Euler angles deviates from Euler angles in code

Hi everyone,

I’m trying to clamp the rotation over the X axis(tilt) so you can not rotate further up than straight up and not further down then straight down. The problem is that the clamp angle seems to be between -90 and 90 if you look at the inspector but if you debug.log the euler angle, it shows that the angle is actually below 90 for every camera tilt downwards. To make it a little bit more clear, if you look straight ahead, the inspector shows 0 and the debug also shows 0. If you look straight down, the inspector shows 90 and the debug also shows 90. If you tilt even further “downwards”, the inspector shows 180, but the debug log shows 0 again. See the screenshot below for an indication.

85428-inspector-shows-a-different-angle-than-it-actually.jpg

This is the code I use to show the euler angle.

Vector3 camEuler = camT.rotation.eulerAngles;
Debug.Log("cam angle " + camEuler.x);

In which camT is the camera transform. Does someone know why this happens?

Kind regards,

Yorick

Reference for pan,tilt,roll:
85429-pan-tilt-roll1.png

There are many ways to express the same rotation:
a rotation of 180 degrees around the y axis is the same as a rotation of 180 degrees around the x axis followed by 180 degrees around the z axis, for example.

Your Debug.Log only looks at the x component of the rotation but, if you look at the eulerAngle Vector as a whole, you’ll probably just see that they are equivalent expressions of the same rotation.