Quick question, I'm trying to get my controller working through code, if I add an event using the project settings, it just works, if I add it through code it doesn't.
This is my current code (only the important parts (to my knowledge)) (got most from a guide that didn't cover controller support.)
const controls: Dictionary[String, Array] = {
"walk_left": [KEY_LEFT, KEY_A, JOY_AXIS_LEFT_X],
"walk_right": [KEY_RIGHT, KEY_D, JOY_AXIS_RIGHT_X],
"jump": [KEY_UP, KEY_W, KEY_SPACE, JOY_BUTTON_A, JOY_BUTTON_B],
"ground_pound": [KEY_DOWN, KEY_S, JOY_BUTTON_LEFT_SHOULDER]
}
var key_to_add
for action in controls:
if not InputMap.has_action(action):
InputMap.add_action(action)
for key in controls[action]:
key_to_add = InputEventKey.new()
key_to_add.keycode = key
#do i have to add something to allow all devices? (Like the button in the project settings)
InputMap.action_add_event(action, key_to_add)
goal:
var direction: float = Input.get_axis("walk_left", "walk_right")
but working with controllers too and not just wasd
Ps: I'm new to posting questions, if anything is unclear or I did something wrong please let me know. :)
Have a nice day!