Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

How to know left or right controller?

How do I know if the controller for my Oculus Go is Left or Right handed in Unity? Is there a simple command to put in an if statement like:

if (Controller is left) {

}

Comments

  • HeyBishopHeyBishop Posts: 16
    NerveGear
    Hi @imperativity,
    It's important to me to be able to determine the handedness too.
    For the Oculus Go, I have the following code:
    Debug.Log("Is L connected: " + OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote));
    Debug.Log("Is R connected: " + OVRInput.IsControllerConnected(OVRInput.Controller.RTrackedRemote));
    
    At runtime (on the device) both lines return: "Is X connected: False".

    So, what am I doing wrong? How does one determine which hand the user is using?

    I got the above code from the following documentation:
    https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/#unity-ovrinput
  • HeyBishopHeyBishop Posts: 16
    NerveGear
    I just checked to see how it's done in the GearVrControllerTest scene provided. It would seem this function doesn't work here either. Was OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote) deprecated?


  • HeyBishopHeyBishop Posts: 16
    NerveGear
    edited December 2018
    OMG! I figured it out!
     OVRPlugin.GetDominantHand();
    It's an enum. With it, I created the following script:

    public class UserHandedness : MonoBehaviour
    {
        public static UserHandedness Status { get; set; }
    
        void Awake()
        {
            if (Status != null && Status != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Status = this;
            }
        }
    
        public bool IsRightie()
        {
            OVRPlugin.Handedness handedness = OVRPlugin.GetDominantHand();
            if (handedness == OVRPlugin.Handedness.RightHanded)
            {
                return true;
            } else
            {
                return false;
            }
        }
    
        public bool IsLeftie()
        {
            OVRPlugin.Handedness handedness = OVRPlugin.GetDominantHand();
            if (handedness == OVRPlugin.Handedness.LeftHanded)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    



    With it, I can do this in any other script:

    if (UserHandedness.Status.IsLeftie())
            {
                Debug.log("You're a southpaw, awesome!");
            }


Sign In or Register to comment.