[A5] Xbox360 Controller Trigger buttons = only one axis?
anto80

Hello all,

I'm using Allegro 5.0.10 and a Xbox360 USB Controller.
I'm using al_get_joystick_state to detects all inputs and store it in ALLEGRO_JOYSTICK_STATE .
All this is perfect except that Left Trigger (LT analog button) works as 3rd axis (Axis[2] negative values 0.0 to -1.0) and Right Trigger (RT analog button) also works as 3rd axis (Axis[2] positive values 0.0 to +1.0).
Thus, when you hold LT and RT these 2 values compensate each other and the result is 0.0, just like none of the 2 buttons where input.

This seems to be a common problem shared on other game engine. For example :

http://answers.unity3d.com/questions/27878/triggers-on-the-360-controller-treated-as-one-axis.html

The problem is:

  • I don't have a 9th or 10th axis like in this given thread.

  • none of the 8 allegro sticks (_AL_MAX_JOYSTICK_STICKS) or 8*3 axes (_AL_MAX_JOYSTICK_AXES) are returning non-zero values. Yes I tested them all.

Did any of you succeeded in detecting LT+RT input?

Thank you

RPG Hacker

One way to fix this could be to use DirectInput correctly or, even better, XInput.

anto80

One way to fix this could be to use DirectInput correctly or, even better, XInput.

Sorry but I'm not following you.
Could you be more specific?
Is your solution Allegro 5.0 standard?
Can you show some code?

SiegeLord

Allegro 5.1 had a lot of work done with joysticks, in particular with XInput. I'd try 5.1 and see if it helps.

torhu

One way to fix this could be to use DirectInput correctly or, even better, XInput.

When I set my Logitech F510 controller to XInput mode, LT and RT are treated as one axis. So I assume XInput wouldn't really help. In DirectInput mode, they are treated as buttons, not sticks. In both cases, Allegro 5.0 and the Game Controllers app that comes with Windows 8.1 give the same result.

I haven't tested with 5.1, can't be bothered to build it...

RPG Hacker

That's weird. Could that be a drivers issue? Or maybe they're even doing this intentionally. I don't know if there actually is a single XBOX 360 game where both triggers have to be used for different things at the same time.

Chris Katko

Has everyone missed the fact that this is by design?

http://wiki.unity3d.com/index.php?title=Xbox360Controller

(see section: Axises)

Go to the Windows joystick calibration screen. It's only one axis because it's supposed to be a linked "throttle and/or brake" axis.

XInput may allow separate per this one:

https://forums.dolphin-emu.org/Thread-l-and-r-trigger-problem

I know some Xbox games got around this limitation, but I've never heard of how they did it.

[edit]

Quote:

If you only build your game for Windows, you may be interested in XInput.NET which allows full XBox 360 controller support. For an InputManager.asset file with four XBox 360 controllers mapped click here or with separate axises for triggers: click here

Windows only

[edit]

Supposedily, you can download the Xbox 360 controller driver:

https://www.microsoft.com/hardware/en-us/d/xbox-360-controller-for-windows

And there's a config program to change whether or not the axies are linked. The point here is that it's not Allegro, and it's not a portable solution.

[edit]

Also, I forgot, don't forget to read Microsoft's insane "official reason":

https://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx

Quote:

However, some functionality provided by XInput will be missing from the DirectInput implementation:

- The left and right trigger buttons will act as a single button, not independently
- The vibration effects will not be available
- Querying for headset devices will not be available

The combination of the left and right triggers in DirectInput is by design. Games have always assumed that DirectInput device axes are centered when there is no user interaction with the device. However, the Xbox 360 controller was designed to register minimum value, not center, when the triggers are not being held. Older games would therefore assume user interaction.

The solution was to combine the triggers, setting one trigger to a positive direction and the other to a negative direction, so no user interaction is indicative to DirectInput of the "control" being at center.

In order to test the trigger values separately, you must use XInput.

Devs are not happy with their explanation. (see comment section)

[edit]

On the brightside, apparently users were so fed up they made their own driver:

http://vba-m.com/forum/Thread-xbcd-0-2-7-release-info-updates-will-be-posted-here

To bring back the functionality that Microsoft ruined. Let's see how the pro-Microsoft people here try and spin this as positive.

Mark Oates

What are you using the triggers for? What game mechanic?

anto80

in some cases, I had to hold both trigger and press another button while holding.

Hold LT+RT and press A, for example.

[Edit]
So I'm skr**ed, right?

Kris Asick

360 controllers were built specifically for XInput. They are able to interact with DirectInput through legacy support, but in doing so, certain things are not supported. One of those in particular being the ability to read the states of left and right triggers independently. Instead, they are reported as a single axis with one of the triggers going positive on the axis, the other trigger going negative. This is by design and there are NO workarounds to this if you stick with using DirectInput.

Instead, either go up to the unstable Allegro 5.1.x branch which I believe supports XInput controllers directly (don't quote me on that, I use 5.0.x), or just code your own XInput support. XInput is extremely easy to use and using it directly will allow you to do things like rumble effects and reporting battery levels, things you can't do with a 360 controller if you stick with DirectInput. ;)

anto80

This seems great!

Are there any Allegro examples which use XInput interaction?

RPG Hacker

Using XInput is also great for providing default controls to players using an XBOX 360 Controller. Since that controller is probably the one being used by the most people for PC games, and since the buttons on the controller are known, you can not only provide good default controls for players using this controller, but you can also directly name the buttons on the controller. So instead of saying "press button 1" or "move axis 3" you could say "press A" or "press right trigger".

Thread #615806. Printed from Allegro.cc