Unity3d WebGL input mapping for Xbox controller

xbox controller unity3d webgl

So, this weekend ludum dare 35 happened and I made my entry using xbox 360 controller as my intended imput source. Only one problem there: no existing input guide spoke of how to map buttons on the Xbox controller for unity3d webGL. And that was my target platform.

So, long story short, here’s what I wasted precious jam time looking for:

xbox controller unity3d webgl input map

xbox_360_controller-button-map

For xbox controller usually you would have the triggers on the back as a 3rd or 5th axis, instead on webGL they are mapped only as standard buttons.

As for the axis: left stick is X and Y axis (as usual), right stick is 3rd and 4th axis.

You can set them like this:

xbox controller unity axis input
xbox controller unity axis input

By the way, there’s a simple way to test these mappings on your own!
You can just use this script:

public class testbuttons : MonoBehaviour
{
    [SerializeField]
    Text t;
    // Update is called once per frame
    void Update()
    {
        t.text = "";
        for (int i = 0; i < 20; i++)
        {
            t.text += "Button " + i + "=" + Input.GetKey("joystick button " + i) + "| ";
        }
    }
}

Make an empty scene, add a UI>Text element and stick this script on it. Then run it and read what turns to true when any button is pressed on your controller.

As easy as pie… unless you are in a game jam frenzy, with severe sleep deprivation and panicking like I was… Want more tutorials like this? Join my newsletter! Want to tell me anything? Hit me up on twitter.

Share
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

2 thoughts on “Unity3d WebGL input mapping for Xbox controller”

  1. Hey! Thanks for this.

    Do you know how to modify this code to get axis? Something like:
    t.text += “Axis” + i + “=” + Input.GetAxis(“joystick axis ” + i) + “| “;

    that returns an error: ArguementException: Input Axis joystick axes 0 is not setup.

    it doesn’t work with “axes” either.

Leave a Reply

Your email address will not be published.