Best method to use a Joystick to control the mouse?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zombieCraig
:warning: Old Version Published before Godot 3 was released.

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?

:bust_in_silhouette: Reply From: Hinsbart

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.

:bust_in_silhouette: Reply From: lollornr

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

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!

zombieCraig | 2016-03-03 18:24

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

lollornr | 2016-03-03 21:22