A Note About Xbox Controllers

Xbox 360 controllers have the unfortunate "feature" of having both triggers being mapped to the same axis on Windows. This means that if you push in both triggers at the same time, they cancel each other out and Unity can't tell that you're pushing either trigger. Thankfully, the triggers are also (sometimes) mapped separately on different axes, though the driver may need to be installed on Windows 7 or older for this to work.

Even so, there are two further complications:

Multiple Xbox Controllers

If more than one Xbox 360 or Xbox One controller is connected, the triggers may or may not work properly, or may or may not be mapped to these separate axes as previously described. This is an issue with Unity itself, not a flaw in cInput. Recent versions of Unity have taken steps to correct this issue, but some problems may still exist. More information about this problem and how it has affected other custom input managers for Unity can be found here: Details on the Xbox 360 Controller Bug in Unity.

Different Gamepad Mappings Per OS

Another complication with using Xbox 360 or Xbox One controllers is that the buttons and axes are mapped differently depending on the OS. In some cases, the Xbox One controller has different mappings from the Xbox 360 controller on the same OS! This makes it difficult to set up a single default configuration which just works for various OSes and platforms.

The Keys class attempts to assist with this, by providing special entries specifically for the Xbox buttons and joysticks for up to four controllers. These entries follow a similar format as follows:

Xbox1A
Xbox1B
Xbox1X
Xbox1Y
Xbox1Back or Xbox1View
Xbox1Start or Xbox1Menu
Xbox1LStickButton
Xbox1RStickButton

Xbox1BumperLeft
Xbox1BumperRight
Xbox1TriggerLeft
Xbox1TriggerRight
Xbox1DPadLeft
Xbox1DPadRight
Xbox1DPadUp
Xbox1DPadDown

Xbox1LStickLeft
Xbox1LStickRight
Xbox1LStickUp
Xbox1LStickDown
Xbox1RStickLeft
Xbox1RStickRight
Xbox1RStickUp
Xbox1RStickDown

For the second, third, or fourth Xbox controllers, simply replace the Xbox1 part at the beginning of the above entries with Xbox2, Xbox3, or Xbox4 respectively.

Additionally, if you want to accept input from any Xbox controller, simply leave the number out entirely. For example, using Keys.XboxA will look for input from any Xbox controller's A button, without regard to the order in which the controllers are connected. This is very useful for single player games where you would like the player to be able to pick up any controller and play. But be warned that this can cause conflicts in multiplayer games where two players' inputs would interfere with each other.

Keep in mind that

results matching ""

    No results matching ""