For now, I use _unhandled_input
to retreive the Vector2 representation of a joystick input with this method
func _unhandled_input(event):
if event is InputEventJoypadMotion or InputEventKey:
update_movement()
func update_movement():
var move_direction : Vector2
move_direction.x = Input.get_axis("MoveLeft", "MoveRight")
move_direction.y = Input.get_axis("MoveUp", "MoveDown")
So I have 4 actions mapped and I virtualy create 2 axis in this update_movement
method BUT the problem is to retain my previous move_direction
when I release the joystick.
As the _unhandled_input
is called for each input, the "x" axis will call, then the "y" which causes a double call that mess up with the joystick vector. So when one of them (x or y) is zero, the other will be set as the last direction of the joystick, forcing the orientation in one of the four cadinal points...
So my question is: is there a way to retreive joystick (x, y) axis directly in a Vector2 or is there another way to retain the last direction of the joystick when it got released ?