+3 votes

Is it possible to set the mouse position in Godot ?

in Engine by (117 points)

Just by curiosity, what kind of gameplay that uses such feature are you going to implement? This could annoy the user very quickly if it gets in his way.

There exist many legitimate uses - for example, in an FPS - to keep the mouse in the center of the screen :P

@keke I would use Input.set_mouse_mode for that.

Personally I'm using it to reset the mouse position after the user clicks and drags to rotate the camera in a map editor. Otherwise every time they rotated the camera the mouse would reappear somewhere else and they'd have to spend a split second searching for it and repositioning it.

1 Answer

+3 votes
Best answer

I think (untested) that get_viewport().warp_mouse(Vector2 to_pos) is meant for this purpose. The docs about it need some more detail (and a typo fix), but looking at the source code it seems to "warp"/relocate the mouse pointer.

by (1,903 points)
selected by

There's also Input.warp_mouse_pos(Vector2 to), which uses global coordinates.

Works great, thanks !

I don't know if yours was a typo or if it was changed, but the actual method is Input.warwarp_mouse_position(Vector2 to)

I assume warwarp is a typo, it should be

Input.warp_mouse_position( Vector2 to )


Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.