Can Godot's input map pass information regarding magnitude?

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

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?

thanks.

:bust_in_silhouette: Reply From: Hinsbart

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()

Example:

func _input(ev):
    if ev.type == InputEvent.JOYSTICK_MOTION && ev.is_action("xyz"):
	#access analogue value via ev.value
	print(ev.value)