How to move mouse cursor?

Godot Version

4.2

Question

So my character is controlled by mouse movement, and I want to teleport it to the position of another node. I want to move the mouse cursor with it. I tried using warp_mouse thingy, but it sends my mouse flying in weird directions.
I think I understand why this is happening, but I still have no idea how to fix it. How do I calculate the right Vector2 to move my mouse to? I have the position I need it to be at. Please help, thank you

What is the script? specifically what are you calling warp_mouse on and with what parameters?

Sorry I’m so late, but here is my thing (it doesnt work)

func teleport_to_wizard() → void:
wizard_position = get_node(“…/wizard”).get_position()
position = wizard_position
Input.warp_mouse(wizard_position)

Sets the mouse position to the specified vector, provided in pixels and relative to an origin at the upper left corner of the currently focused Window Manager game window.

You may need to translate the wizard position to the viewport’s. i.e. taking the wizard’s global position and subtracting the camera’s position

It flings my mouse in a different direction now! Progress, I guess :slight_smile:

I fixed it! Swapped camera position for the position of camera’s top left corner. It kinda works, but only for certain screen resolution. I tweaked it so it works on my screen. Oh well, more problems for future me to solve :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.