Can someone please help me understand how to stop the mouse from going back to the center of the screen? This is all the code needed to re-create. In video to exaggerate issue I use a autoclicker on right mouse button 5ms delay.
var mouseRestorePos: Vector2
var rightClkHeld: bool = false
func _input(event: InputEvent) -> void:
if event is InputEventMouseButton:
var mb: InputEventMouseButton = event
if mb.button_index == MOUSE_BUTTON_RIGHT:
if mb.pressed:
rightClkHeld = true
mouseRestorePos = get_viewport().get_mouse_position()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
elif rightClkHeld:
rightClkHeld = false
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
Input.warp_mouse(mouseRestorePos)
I had idea to do mouse mode invisible and never use captured.
Then just track the mouse and put my own icon over the hidden one, but was trying to avoid this idea.
Your video shows using _input2 which is not a valid override, so you were only demonstrating the old code. The last few posts in that thread I linked has some fairly dire solutions such as while distance_to_old_position < 15: warp and await a frame; but this is still worth a try before making a virtual mouse icon.