Want to watch the video instead?
1. Prerequisites
- Latest Oculus Integration package.
- A minimum Unity version of 2019.4 LTS
You should also have your Unity project set up for Oculus Quest. If you are unsure how that’s done, you can read through the instruction provided in sections 4 and 5 of the Passthrough blog. In addition, you can download the base repository from here.
2. Adding Hand Interactor
Once your Unity project is set up with all the required project settings and packages downloaded. We can start developing for hand interaction.
So let's begin by adding prefabs to the scene which will collectively enable us to use our hands for interaction.
- In the Hierarchy window, delete the
Main Camera
. - Search for
OculusInteractionSampleRig
in the Project window → drag and drop the prefab into the Hierarchy window. - Open the
OculusInteractionSampleRig
prefab to view its children → open theInputOVR
prefab → open theLeftHand
andRightHand
GameObjects. - Search for
HandGrabInteractor
in the Project window → drag and drop the prefab into theHandInteractor
GameObject of bothLeftHand
andRightHand
GameObjects → rename them as HandGrabInteractorLeft and HandGrabInteractorRight respectively.
- Select the
HandGrabInteractorLeft
prefab, drag and drop theLeftHand
GameObject into the Hand parameter of the Hand Ref component. Similarly, drag and drop theRightHand
GameObject into the Hand parameter of the Hand Ref component of theHandGrabInteractorRight
prefab. - Select the
HandInteractor
of theLeftHand
GameObject and drag and drop theHandGrabInteractorLeft
prefab into the Interactor Drivers parameter of the Interactor Driver Group component. Similarly, select theHandInteractor
of theRightHand
GameObject and drag and drop theHandGrabInteractorRight
prefab into the Interactor Drivers parameter of the Interactor Driver Group component.
3. Adding Interactable
Let’s begin with one hand interaction. As the name suggests, this is a type of interaction where we can use only one hand at a time to interact with an object. This can be used in cases where we want to move an object from one place to another i.e simply drag and drop an object from one place to another. To add such a feature:
- Right-click on the Hierarchy window →
3D Objects
→Cube
. - Adjust the scale and transform such as you have a handy-sized cube in front of the camera.
- Select the
3D Cable
GameObject and the following components to i- The Rigidbody component → uncheck the Gravity parameter.
- The Grabbable component
- The Hand Grab Interactable component
- Select the Cube GameObject → under the Grabbable component check the box ✅ for the parameter Transfer Hand On Second Grab, so that the object gets transferred from the current hand to the new one.
- Also, set the Snap Type parameter as None of the Hand Grab Interactable component. This will ensure that the cube does not snap into the hand, instead, it will remain at the point of grab.