Unity Oculus Quest which hand??

I recently just began my journey into making simple games for the Oculus Quest. Going through tutorials and scripting api’s has been quite fun. However, there seems to not be a very descriptive way to determine if something is in the players right hand or left.
Currently, I have made it so I can shoot a gun in vr using the right controller or right hand. Problem I am faced with is, if I pickup the gun with my left hand, I am able to shoot it with my right.

So I ask is there a way to code this so that if the gun only shoots in the hand that is holding it?

Here is my current code:

if(OVRInput.Get(FireR))
{
   nextFire = FireRate;
   allowFire = false;
   simple.FireAway();
}

According to the OVRInput docs:

https://developer.oculus.com/documentation/unity/latest/concepts/unity-ovrinput/

You can specify what controller to check for using a second argument which is an enum type OVRInput.Controller

https://developer.oculus.com/reference/unity/1.43/class_o_v_r_input/

Like so:

OVRInput.Get(FireR, OVRInput.Controller.RTrackedRemote);
OVRInput.Get(FireR, OVRInput.Controller.RTrackedRemote);

Thank you for your idea, however it is one that I have already done and tried many times over. Since this is for the quest RtrackedRemote, does not work. In fact it will not allow the gun to be fired. Rtouch and Active do work, but I can still fire the gun in the left hand using the right trigger.

Basically what I need is if the gun is grabbedby the right hand it fires, but if the it is grabbedby the left hand the right hand is null.

I tried adding the enums last night but unity crashed each time, so either I am doing wrong or unity doesn’t like it.

After going back to the basics, I added a bool. When the right or left grip is being used it allows the gun to be fired by that hand. Funny thing, now it only works in the left hand.

Here is the current code:

void Update()
    {
        if (ovrGrab.isGrabbed)
        {
            if (OVRInput.Get(gripR))
            {
                rightHand = true;
            }
            if (OVRInput.Get(gripL))
            {
                rightHand = false;
            }
            if (nextFire > 0)
            {
                nextFire -= Time.deltaTime;
                allowFire = true;
                return;
            }
            if (allowFire)
            {
                if(OVRInput.Get(gripR))
                {
                  
                    if(rightHand)
                    {
                        if (OVRInput.Get(FireR, handR))
                        {
                            nextFire = FireRate;
                            allowFire = false;
                            simple.FireAway();
                        }
                    }
                }
                else if (OVRInput.Get(gripL))
                {
                    if (!rightHand)
                    {
                        if (OVRInput.Get(FireL, handL))
                        {
                            nextFire = FireRate;
                            allowFire = false;
                            simple.FireAway();
                        }
                    }
                }
            }
        }
    }
}

Okay, so whatever reason, I cannot get the bool to set in the right hand to allow for the gun to fire only in the right hand. I can set it to the left hand just fine. Since the oculus link doesn’t work with the quest, I cannot debug in the editor.
Does anyone see why the bool is not setting when in the rhand?

Now after alot of digging into forums, docs, youtube and many other areas, I just happened to stumble onto my answer. For whatever reason this works. If you are having issues like I was, this should fix your problem. Where I put OVRInput.Button can be assigned as a variable like so :

public OVRInput.Button button;
(OVRInput.Get(OVRInput.Button, OVRGrabbable.grabbedBy.GetController()));

I hope this helps those that need it.

2 Likes