0 votes

Hi !
In the project settings > input map, it is possible to assign 4 axis per stick (which works perfectly fine)
But in code, InputEventJoystickMotion has only 2 informations per stick (vertical or horizontal axis).

How to set the third value (-1, +1) to set full stick mapping ?
It seems to be accessible from the editor internals but not from gdscript api.

SOLVED
for instance :

event = InputEventJoypadMotion.new()
event.axis = JOY_AXIS_0
event.axis_value = -1.0 # or 1.0, depends on the axis direction
InputMap.action_add_event(actionName, event)
in Engine by (82 points)
edited by

1 Answer

0 votes

Ok so InputEventJoystickMotion has two properties that i'm aware of axis and "axis_value"
The axis property lets you know which axis is being pressed

for example:
JOY_AXIS_0 and JOY_AXIS_1 map my joypad's Left analog stick (could be different for you)
and "axis_value" maps the direction that axis is being held:

for another example:

event.axis = JOY_AXIS_0: #horizontal movement (meaning left to right) 
event.axis_value = -4: a #negative value for left and positive value for right

for another extra example:

event.axis = JOY_AXIS_1: #vertical movement (meaning up and down) 
event.axis_value = -4: a #negative value for up and a positive value for down

Haven't read the Docs but pretty sure its in there somewhere, the above info remembered from AHK

by (4,480 points)

Yes, you can retrieve the information like that
(By the way, I get axis_value from -1.0 to 1.0)
But then let's say I store this in a json, There is no way to
put those "negative-positive" information in the input map from code
I mean by using

event = InputEventJoypadMotion.new()
event.axis = JOY_AXIS_0
InputMap.action_add_event(action, event)

When I do that, event.getactionstrength() returns only positive values.
So I have lost the negative values of the stick in the process

Why -4 for the axis_value ?

That -4 was my error drawing from memory

You're correct that the axis_value strength can only be determined from within the range of -1 to +1

But why are you using event.get_action_strength() in lieu of event.axis_value?

Ok solved thank you very much.

(I use event.get_action_strenght() in my code to move the player)

Because what I want to do is allow the user to save custom controller axis mapping.
So when the event arrives, I need to know exactly where he is moving the stick and then store that information. So it representes 8 values in total (counting both sticks).
But there are only 4 available in godot.
Furthermore, in my configuration, I'm able to store only 1 number per event.
As the first axis is 0, I can't save -0 because I lose the "minus" information.
So I created custom numbers:
-1000, -1001, -1002, -1003 which representes JOYAXISXX with the minus sign

So when the user moves the stick, if event.axis_value is negative,
I can store -(event.axis + 1000)
Then when the file is loaded, if the stored axis is negative, I can do

event.axis = -(customAxis + 1000)
event.axis_value = -1.0

What really confused me is that axis_value is in fact the information that stores -1.0 and 1.0 so it gives the 8 values I needed. BUT they are not constants so when running the game it's no longer -1.0 or 1.0.

By some sort of way, the game reads the inputMap, saves the axis_value somewhere invisible and use it to display the correct event.get_action_strenght()

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.
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 webmaster@godotengine.org with your username.