godot doesn't track the mouse position when the mouse isn't moving

Godot Version

4.5.1

Question

I’m making a fnaflike game in godot, I want the camera to rotate whenever the mouse’s x position is higher than a certain amount, or lower than a certain amount, this on it’s own works fine, but when the mouse isn’t moving absolutely nothing happens, the mouse rotating the camera is fine as is, but it just refuses to do so whenever the mouse position isn’t updating.

code is below.

var mousepos = get_viewport().get_mouse_position().x
	var mousex = mousepos
	var inmiddle = 0
	var camy = neck.rotation.y
	#print(mousex)
	#print(mousey)
	@warning_ignore("integer_division")
	if mousex > (gameWidth/3) and mousex < ((gameWidth/3)*2):
		#print("middle")
		inmiddle = 1
		neck.rotation = Vector3(0,camy,0)
	else:
		inmiddle = 0
		
	@warning_ignore("integer_division")
	if inmiddle == 0 and mousex > (gameWidth/2):
		#print("turnright")
		neck.rotation.y -= deg_to_rad(2)
	@warning_ignore("integer_division")
	if inmiddle == 0 and mousex < (gameWidth/2):
		#print("turnleft")
		neck.rotation.y += deg_to_rad(2)

How do you call this code?
Is it placed in any of the *_input() callbacks? or _process()?

I eventually figured this out myself.. before this got accepted, sorry for the trouble to anyone who was gonna help out :sob:

1 Like

Maybe you can post your solution here so that in case someone has a similar problem in the future, they can try your solution.

3 Likes

the solution was to just warp the mouse to it’s own position
probably not the most performant but

Input.warp_mouse(get_viewport().get_mouse_position())

1 Like

If the update code is in mouse motion handler and you want it to execute always, just execute it always (i.e. in _process()), instead of artificially triggering the motion event from _process() by warping mouse to itself every frame. That looks very odd.

1 Like

this is uhh
probably way better so I’m gonna make this the solution