FPS Camera: How does rotate() work exactly?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Annoyed Grunt
:warning: Old Version Published before Godot 3 was released.

Hello!
I’ve been trying to make a first person camera.

var camera = get_node("Camera");
var pitch = rad2deg(camera.get_rotation().x);
var plus_pitch = SENSITIVITY * mouse.relative_y;
var plus_yaw = fmod(SENSITIVITY * mouse.relative_x,360);
camera.global_rotate(Vector3(0,1,0), deg2rad(plus_yaw));
camera.rotate(Vector3(1,0,0),deg2rad(plus_pitch));

This works correctly, I can watch around freely. However the problem arises when I try to limit the camera like so:

plus_pitch = min(plus_pitch, 45 - pitch);
plus_pitch = max(plus_pitch, -45 - pitch);

The problem comes from the fact that apparently, plus_pitch is a negative value. Yet, when I use it with rotate, it causes a positive rotation. Why is this so?
For now, I’ve just switched its sign to do calculations:

plus_pitch *= -1;
plus_pitch = min(plus_pitch, 45 - pitch);
plus_pitch = max(plus_pitch, -45 - pitch);
plus_pitch *= -1;

This effectively limits the camera to a 90° degree angle, but it causes another problem: if i rotate my camera around (to the left and to the right) it starts spinning for no reason at all, as if I was the yaw actually influenced the pitch. I used global_rotate instead of rotate when using the yaw to be sure I didn’t rotate the camera in its space, but rather in world space, so I’m not sure what the problem could be.

TL;DR why does a negative angle cause a positive rotation in rotate()?
why does global_rotate() seem to affect the pitch instead of being, well, global?

I’m not 100% sure I understand the question but I have a strong feeling that your problems might be a result from a fact that by default camera is facing a negative z axis (while I’m assuming you were writing this for positive z).

kubecz3k | 2016-04-11 08:13