+2 votes

Is it possible to set the mouse position in Godot ?

in Engine by (114 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.

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,899 points)
selected by

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

Works great, thanks !

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.