Add Mapping Input for the axes of the analog sticks

Hi All,

I have a question about input-handling in JME 3, How to add mapping input for the axes of analog sticks (x,y) and (z,rz) ?

I’m still confusing which axesId should I used for inputManager.addMapping() .

inputManager.addMapping(“Z Axis”, new JoyAxisTrigger(joystickId, axesId, true/false));


HI baalgarnaal,

I have try your solution before but when I test with Sony Playstation 2 controller is going fine but when I test with another game pad (controller) the mapping of x, y, and z, rz axes are still wrong. And I think the axesId of x,y,rz,z is not in order. So, I have an idea to get x and y axesId from joystick.getXAxisIndex() and joystick.getYAxisIndex(). But, there are still problem how I can get axesId for z and rZ ?

[java]inputManager.addMapping("JoyXY Left", new JoyAxisTrigger(0, joystick.getXAxisIndex(), true));

inputManager.addMapping("JoyXY Right", new JoyAxisTrigger(0, joystick.getXAxisIndex(), false));

inputManager.addMapping("JoyXY Down", new JoyAxisTrigger(0, joystick.getYAxisIndex(), false));

inputManager.addMapping("JoyXY Up", new JoyAxisTrigger(0, joystick.getYAxisIndex(), true));[/java]


I guess there needs to be a way to get all axes and buttons and also get their names, as right now only X and Y axis can be detected

You can find an example in (package jme3test.input):

[java] public void simpleInitApp() {

Joystick[] joysticks = inputManager.getJoysticks();

for (Joystick joy : joysticks){



inputManager.addMapping("DPAD Left", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, true));

inputManager.addMapping("DPAD Right", new JoyAxisTrigger(0, JoyInput.AXIS_POV_X, false));

inputManager.addMapping("DPAD Down", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, true));

inputManager.addMapping("DPAD Up", new JoyAxisTrigger(0, JoyInput.AXIS_POV_Y, false));

inputManager.addListener(this, "DPAD Left", "DPAD Right", "DPAD Down", "DPAD Up");

inputManager.addMapping("Joy Left", new JoyAxisTrigger(0, 0, true));

inputManager.addMapping("Joy Right", new JoyAxisTrigger(0, 0, false));

inputManager.addMapping("Joy Down", new JoyAxisTrigger(0, 1, true));

inputManager.addMapping("Joy Up", new JoyAxisTrigger(0, 1, false));

inputManager.addListener(this, "Joy Left", "Joy Right", "Joy Down", "Joy Up");


As far as I know, axesId values are just in order of what you specified (x = 0, y = 1, z = 2, rz = 3) but I suggest you simply try that by implementing the above in your code and see how your game reacts to your bindings :wink:

I think that is pretty much all the game-specific independent information I can give you :wink:

@momoko_fan yup, we need joystick input-handling more flexible in JME 3 as in JInput have. May JME developers (or you) will fix it soon.