I am making an FPS game and I noticed the mouse inputs are slightly stuttery, and for some frames will be 0 even though I am moving the mouse.
For example, I printed the mouse movement every frame and got something that looked like:
(-0.34188, 0)
(-0.2849, 0)
(-0.34188, 0)
(-0.2849, 0)
(-0.34188, 0)
(0, 0) <— skips a frame
(-0.2849, 0)
(-0.34188, 0)
(-0.2849, 0)
(-0.34188, 0)
(-0.34188, 0)
This slight jitteriness causes the movement to also be jittery which is really noticeable and janky looking. I would like to specify that my mouse mode is set to captured and accumulated input is set to false (although I noticed the issue regardless of whether it was true or false)
This is the code that I use to handle the mouse input:
func _unhandled_input(event) -> void:
if event is InputEventMouseMotion:
r += event.relative * sens * SENS_CONSTANT
and in the _process function:
func _process(delta : float) -> void:
cam.rotation_degrees.x = clamp(cam.rotation_degrees.x - r.y, -90, 90)
cam.rotation_degrees.y = cam.rotation_degrees.y - r.x
print(r)
r = Vector2.ZERO
But im not even sure if the problem is the (0, 0) frames. I tried to make it so if the mouse input randomly switches to (0, 0) for one frame, it will use the previous mouse motion instead:
func _process(delta : float) -> void:
if og_r == Vector2.ZERO and not one_frame:
one_frame = true
else:
r = og_r
if og_r != Vector2.ZERO:
one_frame = false
cam.rotation_degrees.x = clamp(cam.rotation_degrees.x - r.y, -90, 90)
cam.rotation_degrees.y = cam.rotation_degrees.y - r.x
og_r = Vector2.ZERO
But it’s still jittery. I really don’t know what else I could do. Does anyone know how to fix this?