I know it's pretty old topic, but me and my friend trying one of Lukky's Godot tutorials, from youtube. And he did camera rotation for 3rd person view, but without any rotation limit. I googled and found how to that with clamp, but quickly noticed that rotation become broken if I move mouse too fast vertically. Camera leans a bit, and Mathf.clamp stop working. I displayed rotations on a label, and noticed that Y axis changes after quick movements of mouse.
I noticed that this happens only when I do:
Vector3 camera_rot = camMount.Rotation;
camera_rot.X = Mathf.Clamp(camMount.Rotation.X, Mathf.DegToRad(-70), Mathf.DegToRad(70));
camMount.Rotation = camera_rot;
So it's became broken, after I copy rotation to temp Vector3, change it, and then return values back to Rotation property.
It's my first game engine that I try, and I barely coded anything complicated, before, or what's required actual math, so I'm really was confused why this happening. And I'm still confused.
I was able to kinda fix it, by adding
camera_rot.Y = Mathf.Pi;
after clamp.
Now reading this, I see that issue happens because -180deg rotation, and in that tutorial Player base node was rotated 180 Y (and, I guess, I rotated it to -180) , because coordinate system in Godot is different to that from Mixamo or something like that, I'm still not sure.
So I've reset Player rotation to 0,0,0 from -180, and rotated camera to +180.
And now it's not breaking even with craziest mouse moves.
I really wish I able to understand what exactly goes wrong, but even after reading this thread I'm still not sure.