Forum Discussion
andrewThe_Great
8 years agoHonored Guest
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) {
}
if (Controller is left) {
}
3 Replies
Replies have been turned off for this discussion
- HeyBishopProtegeHi @imperativity,
It's important to me to be able to determine the handedness too.
For the Oculus Go, I have the following code:At runtime (on the device) both lines return: "Is X connected: False".Debug.Log("Is L connected: " + OVRInput.IsControllerConnected(OVRInput.Controller.LTrackedRemote));
Debug.Log("Is R connected: " + OVRInput.IsControllerConnected(OVRInput.Controller.RTrackedRemote));
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 - HeyBishopProtegeI 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?
- HeyBishopProtegeOMG!
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!");
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 years ago
- 10 months ago