+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?

thanks.

in Engine by (13 points)
edited by

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

Example:

func _input(ev):
    if ev.type == InputEvent.JOYSTICK_MOTION && ev.is_action("xyz"):
    #access analogue value via ev.value
    print(ev.value)
by (924 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.