# How to map a joystick axis to the inputMap from code ?

**URL:** <https://forum.godotengine.org/t/how-to-map-a-joystick-axis-to-the-inputmap-from-code/14948>\
**Category:** Archive\
**Created:** [November 21, 2020, 3:06pm UTC](https://forum.godotengine.org/t/how-to-map-a-joystick-axis-to-the-inputmap-from-code/14948 "2020-11-21T15:06:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [November 21, 2020, 3:06pm UTC](https://forum.godotengine.org/t/how-to-map-a-joystick-axis-to-the-inputmap-from-code/14948/1 "2020-11-21T15:06:37Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | leo-pnt |

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)

```

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [November 22, 2020, 11:14pm UTC](https://forum.godotengine.org/t/how-to-map-a-joystick-axis-to-the-inputmap-from-code/14948/2 "2020-11-22T23:14:46Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | Wakatta |

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:

```auto
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:

```auto
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

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

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

```

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

Why -4 for the axis\_value ?

leo-pnt | 2020-12-01 11:20

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

Wakatta | 2020-12-01 15:28

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 JOY\_AXIS\_XX 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

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

leo-pnt | 2020-12-02 19:34
