Input.warp_mouse doesn't work as intended after resizing game window

Godot Version

Godot 4.1.2.stable.mono.official


Hey everyone!
I need some help debugging this issue I’m having with the Input.warp_mouse function. I’m trying to move the cursor using a gamepad. It works very well if I don’t resize my screen, in fact it even works as expected when i resize the window horizontally. However when i resize the window vertically the cursor suddenly starts moving very fast, shooting up or down to the corners of the screen.

Here’s my code:
PS: the values i get from the speed curve are consistent when i resize the screen, the curPos value passed into the warp_mouse function is correct.

var input_direction : Vector2 = Input.get_vector("move_left", "move_right", "move_up", "move_down")
		input_direction = input_direction.normalized()
		if input_direction.length() > 0.0:	
			var curPos : Vector2 = get_global_mouse_position()
			curPos.x += input_direction.x * delta * cursorSpeedCurve.sample_baked(moveTime) * cursorSpeedBase
			curPos.y += input_direction.y * delta * cursorSpeedCurve.sample_baked(moveTime) * cursorSpeedBase
			moveTime += delta

Thank you all in advance!

You are mixing different coordinate systems.

  • get_global_mouse_position() returns Canvas Coordinates.
  • Input.warp_mouse(curPos) accepts Screen Coordinates.

You will need to transform the coordinates from one system into the other.
See How to transform screen position to global through a Camera2D? - #2 by Sauermann and How to transform screen position to global through a Camera2D? - #3 by justinjia for documentation links that explain coordinate transforms and the Godot 2D coordinate systems.