Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
andrewThe_Great's avatar
andrewThe_Great
Honored Guest
8 years ago

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) {

}

3 Replies

Replies have been turned off for this discussion
  • 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
  • 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?


  • 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!");
    }