Mouse control while using rotate_object_local

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)

Why is rotation speed calculated as a sum of components of the relative mouse movement?

Is that not correct? Wouldn’t a higher difference in mouse movement mean a higher rotation speed?

Think about it. If you move the mouse diagonally in a direction where relative.x is e.g. -5 and relative.y is 5 - the result will be 0.

Typically you would use a event.relative.length(), this will extract the magnitude of a vector. It is calculated similarly but each component is squared before added, √(x*x + y*y) which is also the pythagorean theorem.