xbox one Controller for Gear VR

I’m working on my first Gear VR project and have just about everything set up, but I can’t seem to map my xbox one controller. I’m referencing the attached xbox one controller image for the input settings, but nothing is working once I build and test on my android/Gear. Is there something I am missing to get the controller to map correctly?

Do you have a Xbox One S controller?

1 Like

Yes I do have the xbox one S controller. I did just realize this morning that I was using the first person controller rather than the ovrcharactercontroller from the oculus sdk, but now I’m reading that the ovrcharactercontroller doesn’t use the input settings for mapping to a controller? So are all inputs for VR mapped through scripting only?

For the GearVR you want to be using either Rewired to handle gamepads, or OVRInput from the Oculus utilities.

A couple relevant links:

I like to write everything myself. I have spent the last day or so writing my own UnityInput system and its not that hard. Rewired I think is great for Desktop use as it used DirectInput/XInput on Windows and on OS X it used the HIDController.h stuff in IOKit.h etc. (I personally have never used it).

For mobile…its over kill…by a long shot.

Save yourself $45 and learn how Inputs are done its REALLY easy.

1.) Auto Generate the InputManager
2.) Test out what the layout for your controller is
3.) Create a container to save the button and axis information
4.)…
5.) Profit

Here are a few things to get you started. This is VERY sloppy as I gutted my project and removed some unnecessary code to make it more generic so don’t judge me!

InputManagerGenerator

#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using System.Collections;

/// <summary>
/// PLACE THIS IN THE EDITOR FOLDER OR PUPPIES WILL DIE
/// </summary>
public class InputManagerGenerator : System.Object {
    [MenuItem("Edit/Project Settings/Auto Generate Input Manager")]
    public static void GenerateInputManager() {
        string path = "ProjectSettings/InputManager.asset";
        SerializedObject asset = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(path)[0]);

        // Unity supports up to 11 joysticks.
        for(int controllerIndex = 1; controllerIndex <= 4; controllerIndex++) {
            // Generate generic buttons.
            for(int buttonIndex = 0; buttonIndex < 20; buttonIndex++) {
                AxisData axis = new AxisData();
                string buttonID = string.Format("joystick {0} button {1}", controllerIndex, buttonIndex);
                axis.Name = buttonID;
                axis.PositiveButton = buttonID;
                axis.Gravity = 1000.0F;
                axis.DeadZone = 0.0F;
                axis.Sensitivity = 1000.0F;
                axis.Type = 0;
                axis.Axis = 0;
                axis.JoyNum = controllerIndex;
               
                InputManagerGenerator.AddAxes(asset, axis);
            }

            // Generate generic axes.
            // Pre Unity5 only 20 axis are supported keep that in mind.
            for(int axisIndex = 1; axisIndex <= 28; axisIndex++) {
                AxisData axis = new AxisData();
                string axisID = string.Format("joystick {0} axis {1}", controllerIndex, axisIndex);
                axis.Name = axisID;
                axis.Gravity = 0.0F;
                axis.Sensitivity = 1.0F;
                axis.DeadZone = 0.0F;
                axis.Type = 2;
                axis.Axis = axisIndex - 1;
                axis.JoyNum = controllerIndex;
               
                InputManagerGenerator.AddAxes(asset, axis);
            }
        }
    }
   
    static void AddAxes(SerializedObject asset, AxisData axis) {
        SerializedProperty axes = asset.FindProperty("m_Axes");
       
        for(int i = 0; i < axes.arraySize; i++) {
            string name = axes.GetArrayElementAtIndex(i).FindPropertyRelative("m_Name").stringValue;
           
            if(name.CompareTo(axis.Name) == 0) {
                return;
            }
        }
       
        axes.arraySize++;
       
        SerializedProperty axisProperty = axes.GetArrayElementAtIndex(axes.arraySize - 1);
       
        axisProperty.FindPropertyRelative("m_Name").stringValue = axis.Name;
        axisProperty.FindPropertyRelative("descriptiveName").stringValue = axis.DescriptiveName;
        axisProperty.FindPropertyRelative("descriptiveNegativeName").stringValue = axis.DescriptiveNegativeName;
        axisProperty.FindPropertyRelative("negativeButton").stringValue = axis.NegativeButton;
        axisProperty.FindPropertyRelative("positiveButton").stringValue = axis.PositiveButton;
        axisProperty.FindPropertyRelative("altNegativeButton").stringValue = axis.AltNegativeButton;
        axisProperty.FindPropertyRelative("altPositiveButton").stringValue = axis.AltPositiveButton;
        axisProperty.FindPropertyRelative("gravity").floatValue = axis.Gravity;
        axisProperty.FindPropertyRelative("dead").floatValue = axis.DeadZone;
        axisProperty.FindPropertyRelative("sensitivity").floatValue = axis.Sensitivity;
        axisProperty.FindPropertyRelative("snap").boolValue = axis.Snap;
        axisProperty.FindPropertyRelative("invert").boolValue = axis.Invert;
        axisProperty.FindPropertyRelative("type").intValue = axis.Type;
        axisProperty.FindPropertyRelative("axis").intValue = axis.Axis;
        axisProperty.FindPropertyRelative("joyNum").intValue = axis.JoyNum;
       
        asset.ApplyModifiedProperties();
    }

    public struct AxisData {
        public string Name;
        public string DescriptiveName;
        public string DescriptiveNegativeName;
        public string NegativeButton;
        public string PositiveButton;
        public string AltNegativeButton;
        public string AltPositiveButton;
        public float Gravity;
        public float DeadZone;
        public float Sensitivity;
        public bool Snap;
        public bool Invert;
        public int Type;
        public int Axis;
        public int JoyNum;
    }
}
#endif

GuiCtrl

using UnityEngine;
using System.Collections;

public class GuiCtrl : MonoBehaviour {
    void OnGUI() {
        for(int i = 0; i < Input.GetJoystickNames().Length; i++) {
            string name = Input.GetJoystickNames()[i];
            Vector2 size = new Vector2(200.0F, 20.0F);
            Vector2 header = new Vector2(i * size.x + 50.0F * i, 0.0F);
           
            Rect bound = new Rect(header.x, header.y, size.x, size.y);
           
            GUI.Label(bound, name);
           
            for(int button = 0; button < 20; button++) {
                string buttonID = string.Format("joystick {0} button {1}", i + 1, button);
               
                Vector2 cell = new Vector2(i * size.x + 50.0F * i, size.y * (button + 1));
                Rect cellBound = new Rect(cell.x, cell.y, size.x, size.y);
                GUI.Label(cellBound, "B: " + button + ": " + Input.GetButton(buttonID));
            }
           
            for(int axis = 1; axis <= 20; axis++) {
                string axisID = string.Format("joystick {0} axis {1}", i + 1, axis);
                Vector2 cell = new Vector2((i + 1) * size.x - size.x / 2.0F + 50.0F * i, size.y * axis - 1);
                Rect cellBound = new Rect(cell.x, cell.y, size.x, size.y);
                GUI.Label(cellBound, axisID + ": " + Input.GetAxis(axisID).ToString("0.0"));
            }
        }
    }
}

Use the GuiCtrl thingy I made so you can see what axis/buttons respond to input. Keep in mind, that these inputs change from platform to platform and within those platforms as well as drivers index buttons differently. I.E. some triggers respond as button and some triggers range from -1.0F to 1.0F rather than 0.0F to 1.0F.

Formula to Adjust Unwanted Raw Trigger Values.

        // Get the raw value
        float rawValue = Input.GetAxisRaw("SOME_AXIS");
        // What is the source range? MIN to MAX
        // in this case -1.0F to 1.0F
        // pass the rawValue so it can figure out where
        // the rawValue resided betweent he MIN and the MAX
        // it returns 0.0F to 1.0F
        // 0.0F being at the MIN value 1.0F at the MAX value.
        // For example.
        // rawValue = 0.0F
        // MIN = -1.0F MAX = 1.0F
        // rawValue is between or 50%
        // inverseLerp = 0.5F; // 50% or 0.5F
        // target value is 0.0F to 1.0F
        // 50% of that is 0.5F
        // adjustedValue = 0.5F
        float inverseLerp = Mathf.InverseLerp(-1.0F, 1.0F, rawValue);
        // adjust the rawValue to your target MIN and MAX value.
        float adjustedValue = Mathf.Lerp(0.0F, 1.0F, inverseLerp);

Hope that helps!