+1 vote

I've noticed that Godot has an input map which allows you to define "strings" which correspond to specific input. I have a joystick which has an "axis" as a button so that the button can be depressed 50% and it sends the magnitude (0.5) to the program (i.e. the axis reads between 0.0 and 1.0 showing how far down the button is pushed).

From what I can see, Godot's input system is binary -- either the button is slightly pressed or it isn't -- and anything that requires the magnitude needs to be explicitly defined as a joystick axis.

I used to play around with GLFW and have a working event handler that gets around this issue -- keyboard keys give a magnitude of either 0.0 or 1.0, and if I map an axis to the button it sends a magnitude between 0.0 and 1.0 which allows for much greater flexibility.

So I'm curious: why not define this input map to have both a name (i.e. what you search for in is_action_pressed(...)) and a magnitude? Is there no way in the current input map system to define this behaviour, and if not: why not?


asked Aug 10, 2016 in Engine by kev717 (13 points)
edited Aug 10, 2016 by volzhs

1 Answer

+2 votes

The InputMap action system is meant for UI navigation and one-shot gameplay code.
If you need to access analogue values, be it gamepad axes or mouse/touchscreen input, you'll have to use the _input callback function.
Note that you can still assign your joystick axis to an InputMap action for string access, just use is_action() instead of is_action_pressed()


func _input(ev):
    if ev.type == InputEvent.JOYSTICK_MOTION && ev.is_action("xyz"):
    #access analogue value via ev.value
answered Aug 11, 2016 by Hinsbart (914 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 How to use this Q&A? before posting your first questions.