Godot Version
4.6.1
Question
I have a basic script that allows for first-person camera rotation. However since the game I am making has the player character be able to turn in any direction (the game takes place in zero gravity), I’ve used “rotate_object_local” to make sure that the mouse still controls the character appropriately no matter what angle the character itself is at.
However, I realized a problem: The rotation from the mouse movement is only on or off. Moving the mouse fast or slow doesn’t change the speed of the character’s rotation. This is very awkward gameplay-wise and so I’ve been trying to fix it.
I had the idea to try and make the mouse sensitivity change based on the change in mouse position, to recreate what should happen normally. I created a “rotationspeed” var and tied it to the change in mouse position. While this technically works I’ve noticed that if I were to move the mouse very quickly, the character will “lock up” in a sense, not turning as quickly as it should.
My code for the character rotation is as follows:
func _unhandled_input(event):
if event is InputEventMouseMotion:
# rotate camera by how much the mouse is moving * mouse sensitivity
rotationspeed = abs(event.relative.y + event.relative.x) * 0.0025
event.relative = event.relative.normalized()
rotate_object_local(Vector3(-event.relative.y, -event.relative.x, 0), rotationspeed)