Godot Version
4.6.1
Question
I have a first-person game, which takes place in zero-gravity. That means that from a gameplay standpoint, I want the player to not have a “up” direction. No matter what rotation their character is code-wise, the player can still turn as if they are aligned upwards.
Take for example a situation where the character is made to be facing towards “down”. If I were to move my mouse to the left of the screen, the ideal behavior would be that the character would rotate left, as if they were standing on a surface and turning. However, instead the character just spins around. The reason being that even though they are facing downwards, the game still treats the mouse movements as if the character was perfectly upright. So when moving the mouse to the left, the game rotates the character left relative to the game world, but not to the character itself.
The code for the player character’s rotation is as follows:
if event is InputEventMouseMotion:
# rotate camera by how much the mouse is moving * mouse sensitivity
if self.rotation_degrees.x > 90 or self.rotation_degrees.x < -90:
self.rotate_y(-event.relative.x * SENSITIVITY)
else:
self.rotate_y(event.relative.x * SENSITIVITY)
self.rotate_x(-event.relative.y * SENSITIVITY)