Is joystick mapping/trigger fully supported?

Hi everyone and happy new year.



I would like to manage joystick inputs as mentioned here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:input_handling but there’s 2 problems.


  1. All directions work but south/east. Both south and east work nice separately but south+east at the same time trigger north+west, and only with joystick. Is it a known issue?


  2. I didn’t find the way to use joystick buttons.



    Thanks.

1-For combined actions take a look at TestComboMoves.java

2-Make sure you enable the joyinput :

[java]

settings.setUseJoysticks(true);

[/java]

You can get a list of joysticks through InputManager.getJoysticks(), these have helper methods to map the buttons/axes to the mappings

thanks you guys for replies,



@glaucomardano: I guess I don’t need combo management to go down/right, it’s not a combo but a single direction and it works with keyboard, but not with explanations showed in the links above. And yes I setted setUseJoysticks() to true, otherwise no axis would work.



@Momoko_Fan: thanks to your method I was able to mapping a fire button but something strange happends:

this is the keyboard mapping:

[java]

inputManager.addMapping(“North”, new KeyTrigger(KeyInput.KEY_UP));

inputManager.addMapping(“South”, new KeyTrigger(KeyInput.KEY_DOWN));

inputManager.addMapping(“East”, new KeyTrigger(KeyInput.KEY_RIGHT));

inputManager.addMapping(“West”, new KeyTrigger(KeyInput.KEY_LEFT));

inputManager.addMapping(“Fire1”, new KeyTrigger(KeyInput.KEY_SPACE));

[/java]



and this is the joystick mapping:

[java]

joysticks = inputManager.getJoysticks();

joysticks[0].assignAxis(“North”, “South”, joysticks[0].getYAxisIndex());

joysticks[0].assignAxis(“East”, “West”, joysticks[0].getXAxisIndex());

joysticks[0].assignButton(“Fire1”, 0);

[/java]



With keyboard it’s perfect but with joystick “North” and “South” are inverted. I assume that the up direction of my joystick (gamepad cross) is Y positive right? but it’s inverted. If I switch the positive and the negative mapping it works… even South+East :slight_smile:

@accionmutante: The indexes of buttons and joy-axes are not always the same (I think that’s a driver issue). I have 2 gamepads and they have different indexes for most buttons and joy-axes.



So if you’re going to support joysticks/pads you’ll have to write a configuration-menu if you want to get sure that everybody can play your game.

Also, since I don’t know how you are mapping those to actual movement… and I don’t know how you decided that the axis is backwards, I will mention that if North, South, East, West relate to the x,z plane… the north is negative and south is positive. This is opposite of east/west where east is positive and west is negative.

@ceiphren: that’s what I was afraid of… thanks for the tip, I’ll think about it.



@pspeed: yes I figured it out, in my game north is managed along -z and south along positive z.



Thank you for replies.

Hehe the inverted axis is a common problem, that nearly every game has, cause there is no way to do it right. Every Joystick/Gamepad manufacturer uses a secret golden dice to determine wich way the axis is going.

And the good pads even let you switch that so you can remedy games of silly developers that don’t at least add “invert y axis” :wink: