Repository: godot
Issue: Mouse jumps to random positions upon moving, when mode is set to confined and if warp mouse is used
Labels: bug,topic:input

### Tested versions

Reproducible in 4.3 while using Macos and Windows, have not used in later/earlier versions

### System information

MACOS Sonoma 14 - Godot 4.3 - Vulkan 1.2.283 - Forward+

### Issue description

As said in the title, setting mouse mode to confined/confined hidden while using warp mouse commands in the main loop causes mouse to jump to a random position if movement is detected.

In my code, the cursor sprite has different behaviors that depend on what the player is doing (Sliding, taking knockback, scanning enemies, etc.) and it moves to a position relative to the player/enemy while these actions occur.
Upon finishing these actions, if the mouse mode is confined, on the first frame of moving the mouse will cause it to jump to a random position on the screen (Usually closeby, but still very noticable).

Note that it does **NOT** jump to these positions **immediately after** finishing the action (When warp mouse is called). You can see in the test where I leave the mouse confined that it is still on the cursor sprite **UNTIL I try to move the mouse**, which is when it "teleports". I also checked the mmouse global position and viewport position, and they also do not change **UNTIL I try to move the mouse.**

This only works in confined/confined hidden, and letting the mouse roam free doesn't reproduce this issue, although it's still annoying for when the game is set to windowed mode. This is not dependant on the viewport either, as the problem persists on windowed, fullscreen, borderless, etc.

https://github.com/user-attachments/assets/6288d0e3-f515-4277-94d0-77df3d261ac8


### Steps to reproduce

Here's the mandatory code to reproduce it on a base Sprite2D with a parent class Characterbody2D. There are some variables in this code that belong to the Characterbody, which are in bold.

An explanation of some of the variables:
-**Knockback/Paralyzed**: Mouse movement gets restricted and follows the sprite, in the code below. Player gets pushed back and looks at a position: **enemypos**
-**Interacting**: Similar to knockback and paralyzed, but instead the player stays still and looks at an object of interest: **interact_target**
-**Sliding**: A slide/dodge across the floor for about 2 seconds which restricts mouse movement, in the code below. Moves the sprite in front of the player and warps the mouse to the sprite.

These variables aren't mandatory but hopefully they give better insight on why this is happening, although I doubt it's their issue and I mainly suspect the mouse mode or the warp_mouse function.

This is the only script that alters mouse/cursor movement in the whole project:

	extends Sprite2D

	@onready var Player: CharacterBody2D = get_parent() #Some characterbody2d

	func _ready():
		Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)

	func _physics_process(delta):
		if Player.**knockback** or Player.**isparalyzed**:
			self.position = self.position.lerp(Player.position + (Player.position.direction_to(Player.**enemypos**) * 200), delta * 10) #Moves the sprite slightly in front of the player
			Input.warp_mouse(get_viewport_transform() * global_position) #Warps the mouse to the sprite position

		elif Player.**interacting**:
			self.position = self.position.lerp(Player.position + (Player.position.direction_to(Player.**interact_target**.global_position) * 200), delta * 10) #Moves the sprite slightly in front of the player
			Input.warp_mouse(get_viewport_transform() * global_position) #Warps the mouse to the sprite position
		elif !Player.**knockback** and !Player.**interacting**:
			if Player.**sliding**:
				self.position = self.position.lerp(Player.position + (Player.position.direction_to(Player.slidelook) * 200), delta * 10) #Moves the sprite slightly in front of the player
				Input.warp_mouse(get_viewport_transform() * global_position) #Warps the mouse to the sprite position
			elif !Player.**sliding**:
				self.position = self.position.lerp((get_global_mouse_position() + Vector2(0,-1)), delta * 30) #If the player isn't performing any special action, mouse moves freeform and sprite follows the mouse with a slight offset, so the mouse's tip is on the center of the sprite
				if canprocess and Input.is_action_pressed("special"):
					Input.warp_mouse(get_viewport_transform() * global_position) #If currently scanning an enemy, moves the mouse to the enemy currently being scanned, separate function not included here that moves the sprite to enemy position as well

### Minimal reproduction project (MRP)

N/A