Search Unity

Where can I find the button mappings for XBO?

Discussion in 'Windows' started by MrDude, Jul 31, 2016.

  1. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I just spent the last 4 hours of my life combing through MSDN, Unity docs and Google looking for the joypad mappings to set in the Input section to use my XBO controller in Unity.

    Could that info BE any more well hidden?

    Can someone please link me to the webpage in fairyland where this magical configuration information is stored, please?

    I will clap my hands and repeat "I believe in fairies" if that will help, but can someone just link me to this most rare piece of info, please? I have already wasted half my day on this and really don't want to waste the entire day on something that should only take about 5 minutes to setup...

    Thanks
     
  2. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Well I figured most of it out on my own yesterday and seeing as how apparently not a single person in the world knows the button mapping for an xbox controller I figured I would share my code here for all to use... but I hit a snag and now I really do need someone to help me out a this makes absolutely no sense at all...

    So from what I was able to piece together, A,B,X,Y,Start, Select (or whatever you call them nowadays) and the two joystick clicks, those are actual buttons you can test for using the KeyCode enum and GetKey. Everything else, though, need to be setup in the Input section and tested for using GetAxis. The D-Pad is not 4 buttons, it is 2 axis... the trigger buttons are not 2 buttons, they are one axis...

    And THAT is the part that has my mind going "WTF???" The left and the right trigger use the same axis... Now if that meant that the left trigger worked from -1..0 and the right trigger worked from 0..1 then I would have no problems with this... But the fact is, it starts off at 0 before you press it and then, when you pull either trigger it goes to -1 and when you release it it goes to 1, never again going to 0.

    So how in the world do you use THAT???? That makes absolutely no sense at all.....
    Can anyone please give me some insights into this phenomenon?

    Using 5.4.0f in case that makes a difference.

    Thanks
     
  3. BrotenStudios

    BrotenStudios

    Joined:
    Feb 13, 2014
    Posts:
    155
    The new controller has moved the left trigger to Z axis and the right trigger to Z rotation.
    The older Xbox 360 controller has a negative and positive Z axis for the left and right triggers.
     
  4. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Thanks for the assist. I managed to get it sorted out via trial and error. I was thinking of including it as a free addition to my Core product but since I have not tested this on Mac yet and since there didn't seem to be much interest in this I figured nobody would miss it :)

    At least it's available now to anyone else who asks. Thanks for the assist, though. Appreciate it.
     
  5. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    Same kind of problem here @MrDude.
    This is my configuration, and triggers and axis do not works like they should.



    RT/LT = not work
    RIGTH STICK AXIS = not work
    LEFT STICK AXIS = weird...
    D-PAD = not work

    What am I missing???? This is the sort of thing that makes Unity behind others PRO engines. A entirely day to configure a simple joystick and I face the same error reported from users MONTHS ago.
    Sometimes I think this things doesn't work like it should intentionally, to move the Asset Store.

    [EDIT:]
    Here's a github project that is actually for X360 but works on XONE. The guy mapped Xinput api using XinputDotNet, and is doing the hardwork for Unity.

    https://github.com/JISyed/Unity-XboxCtrlrInput
     
    Last edited: Aug 17, 2016
  6. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    I have a bunch of kits in the store and almost all of them require my Core kit to work. I've decided to add all button mappings I can get as part of that. All my existing customers get it free, new customers get it as part of the $5 kit.

    Currently have Vita and XBO in there. 0 configuration on your end. Just install my kit, plug in your controller and start using as simply as
    Code (csharp):
    1. if (mbsXboxInput.left_bumper) jump();
    Check out my Facebook page...I'm currently looking for beta testers to test on Mac and to verify Windows wireless works the same as Windows usb. Don't want to assume that working through the sensor won't go through custom software/drivers/mapping software etc that will break it...

    So yeah, I managed to get it working now looking fir people to test it. Then I can get to work on the PS4 controller...
     
  7. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    @MrDude, unfortunatelly I don't have a Mac to help you to test.
    As I am not doing anything professional, I don't see why purchase your package for now.
    But to be registered for future purposes, your solution works with what kind of controllers? X360, XONE, PS2/3/4?

    The github project that I mentioned above works like a charm for me with XONE. I want to improve it, since it's using XinputDotNet and I think could be a generic solution for a large range of controllers (at least for Windows).
     
  8. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Yeah, didn't mean you should buy :p Meant to say "see if I can give you my entire kit for free" :p I will happily give you the xbox code only if you wanted it but it seems you are sorted. Currently my solution includes Vita and XBO controllers. Plan on adding more once I have their mappings. All my customers then get all of them free (since they all need that kit anyway so they will have it already and I just keep adding them into there).

    Before @BrotenTechCorp 's post I thought the XBO and 360 mappings were identical but I guess I am wrong. For now I am looking for Mac users and I am looking for a Windows user that has a wirelessly connected controller to test my XBO mappings then I will be moving on to 360 and PS4 controllers. After all, it's pretty basic stuff, just need to know which input is which... Asking for help proved useless. Trial and error had me sorted in a few hours.

    Code (csharp):
    1.     static public class mbsXboxInput
    2.     {
    3.         static public bool a_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton0); } }
    4.         static public bool b_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton1); } }
    5.         static public bool x_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton2); } }
    6.         static public bool y_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton3); } }
    7.         static public bool left_bumper_up { get { return Input.GetKeyUp(KeyCode.JoystickButton4); } }
    8.         static public bool right_bumper_up { get { return Input.GetKeyUp(KeyCode.JoystickButton5); } }
    9.         static public bool select_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton6); } }
    10.         static public bool start_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton7); } }
    11.         static public bool l3_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton8); } }
    12.         static public bool r3_button_up { get { return Input.GetKeyUp(KeyCode.JoystickButton9); } }
    13.  
    14.         static public bool a_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton0); } }
    15.         static public bool b_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton1); } }
    16.         static public bool x_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton2); } }
    17.         static public bool y_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton3); } }
    18.         static public bool left_bumper_down { get { return Input.GetKeyDown(KeyCode.JoystickButton4); } }
    19.         static public bool right_bumper_down { get { return Input.GetKeyDown(KeyCode.JoystickButton5); } }
    20.         static public bool select_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton6); } }
    21.         static public bool start_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton7); } }
    22.         static public bool l3_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton8); } }
    23.         static public bool r3_button_down { get { return Input.GetKeyDown(KeyCode.JoystickButton9); } }
    24.  
    25.  
    26.         static public bool a_button { get { return Input.GetKey(KeyCode.JoystickButton0); } }
    27.         static public bool b_button { get { return Input.GetKey(KeyCode.JoystickButton1); } }
    28.         static public bool x_button { get { return Input.GetKey(KeyCode.JoystickButton2); } }
    29.         static public bool y_button { get { return Input.GetKey(KeyCode.JoystickButton3); } }
    30.         static public bool left_bumper { get { return Input.GetKey(KeyCode.JoystickButton4); } }
    31.         static public bool right_bumper { get { return Input.GetKey(KeyCode.JoystickButton5); } }
    32.         static public bool select_button { get { return Input.GetKey(KeyCode.JoystickButton6); } }
    33.         static public bool start_button { get { return Input.GetKey(KeyCode.JoystickButton7); } }
    34.         static public bool l3_button { get { return Input.GetKey(KeyCode.JoystickButton8); } }
    35.         static public bool r3_button { get { return Input.GetKey(KeyCode.JoystickButton9); } }
    36.  
    37.         static public float left_horizontal { get { return Input.GetAxis("mbsLeftHorizontal"); } }
    38.         static public float left_vertical { get { return Input.GetAxis("mbsLeftVertical"); } }
    39.         static public float right_horizontal { get { return Input.GetAxis("mbsRightHorizontal"); } }
    40.         static public float right_vertical { get { return Input.GetAxis("mbsRightVertical"); } }
    41.         static public float left_shoulder { get { return Input.GetAxis("XBOLeftTrigger"); } }
    42.         static public float right_shoulder { get { return Input.GetAxis("XBORightTrigger"); } }
    43.         static public float dpad_horizontal { get { return Input.GetAxis("XBODPadHorizontal"); } }
    44.         static public float dpad_vertical { get { return Input.GetAxis("XBODPadVertical"); } }
    45.  
    46.     }
    47. }
    48.  
    With this you can test for key down, key up and key being held down. The axis are as follows:
    And that is all there is to it...

    Looking at your screenshot you seem to have all the axis right but your settings for the triggers are different from all your others. look at your snapping, sensitivity, gravity, the fact that you have the triggers setup to only use mouse input... Perhaps that is why it didn't work for you?
     
    Last edited: Aug 17, 2016
    KazYamof likes this.
  9. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    Test scene... Drag onto any game object and hit play...
    Code (csharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using MBS;
    6.  
    7. public class ControllerMapTest : MonoBehaviour {
    8.  
    9.     void OnGUI()
    10.     {
    11.         GUILayout.BeginArea(new Rect((Screen.width / 2f) - 200f, 50f, 400f, Screen.height));
    12.         GUILayout.Label(string.Format("A Button pressed: {0}", mbsXboxInput.a_button));
    13.         GUILayout.Label(string.Format("B Button pressed: {0}", mbsXboxInput.b_button));
    14.         GUILayout.Label(string.Format("X Button pressed: {0}", mbsXboxInput.x_button));
    15.         GUILayout.Label(string.Format("Y Button pressed: {0}", mbsXboxInput.y_button));
    16.         GUILayout.Label(string.Format("Pause Button pressed: {0}", mbsXboxInput.select_button));
    17.         GUILayout.Label(string.Format("Start Button pressed: {0}", mbsXboxInput.start_button));
    18.         GUILayout.Label(string.Format("L1 Button pressed: {0}", mbsXboxInput.left_bumper));
    19.         GUILayout.Label(string.Format("L2 Button value: {0}", mbsXboxInput.left_shoulder));
    20.         GUILayout.Label(string.Format("L3 Button pressed: {0}", mbsXboxInput.l3_button));
    21.         GUILayout.Label(string.Format("R1 Button pressed: {0}", mbsXboxInput.right_bumper));
    22.         GUILayout.Label(string.Format("R2 Button value: {0}", mbsXboxInput.right_shoulder));
    23.         GUILayout.Label(string.Format("R3 Button pressed: {0}", mbsXboxInput.r3_button));
    24.         GUILayout.Label(string.Format("D-pad Vertical value: {0}", mbsXboxInput.dpad_vertical));
    25.         GUILayout.Label(string.Format("D-pad Horizontal value: {0}", mbsXboxInput.dpad_horizontal));
    26.         GUILayout.Label(string.Format("Left Stick Horizontal: {0}", mbsXboxInput.left_horizontal));
    27.         GUILayout.Label(string.Format("Left Stick Vertical: {0}", mbsXboxInput.left_vertical));
    28.         GUILayout.Label(string.Format("Right Stick Horizontal: {0}", mbsXboxInput.right_horizontal));
    29.         GUILayout.Label(string.Format("Right Stick Vertical: {0}", mbsXboxInput.right_vertical));
    30.         GUILayout.EndArea();
    31.     }
    32.  
    33. }
     
    KazYamof likes this.
  10. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,633
    The trigger and other problems on XBone controllers on Windows 10 (and inconsistency between Windows Vista/7/8 and 10) are due to continuing driver changes by Microsoft. Windows 10 launched with the same controller layout as Windows 7, then a few months after release, MS updated the XBone driver and inadvertently changed the L/R triggers to separate them into their own axes, effectively breaking XBone controllers in Unity. On August 2, they released the Windows 10 Anniversary Update which reverted this mistake they made a year before. So when talking about XBone Controller on Windows, you've got at least 4 different driver versions in the wild that affect mappings: Windows < 10, Windows 10 release, Windows 10 broken update, and Windows 10 AU. You can't just get the layout once and have it work across all systems.

    The triggers in < Win 10, Win 10 release, and Win 10 UA are a shared byte just like as it has been on Xbox 360 controller for years. The rationale for this can be found here: https://msdn.microsoft.com/en-us/library/windows/desktop/ee417014(v=vs.85).aspx

    What you are seeing with the 0 start value is purely a Unity thing. Unity clears input values to 0 on start (well, not cleared, but defaulted), when you click out of the window, when you call Input.ResetInputAxes, and sometimes when you unplug another controller (on some OS's). If the axis's rest point doesn't correspond to 0, then you end up with an incorrect value when the axis is cleared.
     
    Last edited: Aug 19, 2016
  11. BrotenStudios

    BrotenStudios

    Joined:
    Feb 13, 2014
    Posts:
    155
    I have
    • Xbox One Bluetooth controllers,
    • Xbox One USB,
    • Xbox 360 USB,
    • PS4 controller,
    • Nvidia Shield Controller,
    • Wii Mote
    I can test on
    • Windows Enterprise 10.0.14393.103,
    • Windows Enterprise 10.0.10586.545,
    • Windows Enterprise 10.0.10240.17071,
    • Xbox One August 2016 QFE 1 (10.0.14393.1040),
    • Nvidia Shield 3.x,
    • OS X 10.8.1,
    • OS X 10.11 "El Capitan",
    • macOS 10.12 "Sierra"
     
  12. BrotenStudios

    BrotenStudios

    Joined:
    Feb 13, 2014
    Posts:
    155
  13. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,569
    That is a very decent resource there, thanks. One or two things I would change but overall a much more elegant solution than mine and it handles multiple controllers. Really worth looking at. Thanks.
     
    Last edited: Aug 29, 2016
  14. BrotenStudios

    BrotenStudios

    Joined:
    Feb 13, 2014
    Posts:
    155
    Correct this is a good start point. It was never intended as a finished script. Nvidia made it as a quick sample as to how to universally map controllers. Much improvements are needed in it.