cancel
Showing results for 
Search instead for 
Did you mean: 

How to get current hand to only fire gun in Unity3d?

starmind001
Explorer
For Christmas, my lovely wife got me the new Oculus Quest and I have played it almost everyday since. Of course, it all comes down to making our own games and I am at a stand still with a problem. When I pick up a gun and press the index trigger to fire it works great. However, it doesn't seem to matter which hand it is in when fired. I can have it in my left hand and fire it with my right.
 To correct this I added a bool and now it only fires in the left hand. I can place it in my right hand and I can still fire it with the left. It has become a flip flop mess. All I want to do is if it is in the right hand I can fire it with the right hand and not the left. And then vice versa.

My Question is, How do I get the current hand and make sure the other cannot preform the same action, but allow for say pickup ammo or blocks??

Here is my 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();
                        }
                    }
                }
            }
        }
    }
}
[code\]
1 ACCEPTED SOLUTION

Accepted Solutions

starmind001
Explorer
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 :
Code (CSharp):
  1. public OVRInput.Button button;
Code (CSharp):
  1. (OVRInput.Get(OVRInput.Button, OVRGrabbable.grabbedBy.GetController()));
I hope this helps those that need it.

View solution in original post

1 REPLY 1

starmind001
Explorer
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 :
Code (CSharp):
  1. public OVRInput.Button button;
Code (CSharp):
  1. (OVRInput.Get(OVRInput.Button, OVRGrabbable.grabbedBy.GetController()));
I hope this helps those that need it.