+2 votes

I want to be able to support both keyboard, mouse and joystick controls. However, when using a joystick I would like that to be the only control necessary. So I would need to use the joystick to control the mouse.

What is the best way to handle mouse movements with the Axis controls of the joystick?

in Engine by (58 points)

2 Answers

0 votes
Best answer

You can use Input.warpmousepos(Vector2 pos) to set mouse position.
Combining axis and current position you can increment a vector2 and then set the new position.

by (56 points)
selected by
This does appear to work.  I've added some sample code:

const MAX_MOUSE_SPEED = 25

func _input(event):
    if event.is_action("ui_axis_up"):
        Input.warp_mouse_pos(self.get_global_mouse_pos() + Vector2(0,-MAX_MOUSE_SPEED * -Input.get_joy_axis(0,1)))

That seems to function, albeit not smoothly yet, but I think I'm on the right track.  Thanks!
Try using Input.is__action__pressed("ui__axis__up") in process! Because input is triggered every input and process have delta parameter to smooth the movement
–1 vote

Sorry, but I think that this isn't (easily) possible. I guess you would have to re-implement the entire mouse cursor logic yourself, as there is (afaik) no way to set the mouse position manually in godot.

You can open an issue github about this, tho we'll have to see if it's feasible on all (desktop) platforms.

by (924 points)
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 Frequently asked questions and 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 [email protected] with your username.