Add this to a Node's script:
func _input(event):
if event is InputEventJoypadMotion:
print(
"Device: %s. Joypad Axis Index: %s. Strength: %s."
% [event.device, event.axis, event.axis_value]
)
It should print the device number and the axis index every time you move an analog stick. If it doesn't print anything, then Godot's not detecting your controller.
Once you know the device number and the axis index, you can make that axis trigger an action:
- Open the Input Map.
- Find or create an action that will be triggered by the analog stick. As an example, I will use the action named ui_left.
- To the right of that action, press the plus button.
- Select "Joy Axis".
- Set the "Device" to the one with the number you determined before.
- Set the "Joypad Axis Index" to the one with the number you determined before.
- Click "Add".
Now that the action is triggered by the analog stick, you can make the player respond to that action:
func _physics_process(delta):
if Input.is_action_pressed("ui_left"):
# Strength will be a number between 0 and 1. 0 means that
# the axis isn't being pushed at all. 1 means that the
# axis is being pushed all the way. 0.5 means that the
# axis is being pushed halfway.
var strength = Input.get_action_strength("ui_left")
position.x -= 250 * strength * delta