Create Distance Grab Interactions
In this tutorial, you learn how to use distance grab interactions to grab a far away cube with your hands, controllers, or controller driven hands. To try distance grab interactions in a pre-built scene, see the
DistanceGrabExamples scene.
Add Distance Grab Interactors
Distance grab interactors let you initiate a distance grab with your hands, controllers, or controller driven hands. There are two types of distance grab interactor, DistanceHandGrabInteractor for hands and controller driven hands, and ControllerDistanceGrabInteractor for controllers.
Adding Distance Hand Grab Interactors to Hands
- Open the Unity scene where you set up your hands.
Under Project, search for DistanceHandGrabInteractor, and drag the DistanceHandGrabInteractor prefab from the search results onto OVRInteraction > Hands > LeftHand > HandInteractorsLeft.
- Under Hierarchy, select HandInteractorsLeft.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add a new element to the Interactors list.
Set the element to DistanceHandGrabInteractor by dragging DistanceHandGrabInteractor from Hierarchy to the element’s field.
- Repeat these steps for the right hand.
Adding Distance Hand Grab Interactors to controller driven hands
- Open the Unity scene where you set up your controller driven hands.
Under Project, search for DistanceHandGrabInteractor, and drag the DistanceHandGrabInteractor prefab from the search results onto OVRInteraction > ControllerHands > LeftControllerHand > ControllerHandInteractors.
Your hierarchy should look like this.
- Under Hierarchy, select LeftControllerHand > ControllerHandInteractors.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add an element to the Interactors list.
Set the element to DistanceHandGrabInteractor.
- Repeat these steps for the right controller hand.
Adding Controller Distance Grab Interactors to Controllers
- Open the Unity scene where you set up your controllers.
Under Project, search for ControllerDistanceGrabInteractor, and drag the ControllerDistanceGrabInteractor prefab from the search results onto Controllers > LeftController > ControllerInteractors.
Your hierarchy should look like this.
- Under Hierarchy, select LeftController > ControllerInteractors.
- Under Inspector, in the Best Hover Interactor Group component, click the + to add an element to the Interactors list.
Set the element to ControllerDistanceGrabInteractor.
- Repeat these steps for the right controller.
Add Distance Grab Interactable
A distance grab interactable lets you grab the object it’s attached to from a distance. There are two type of distance grab interactable, one for grabbing objects using controllers, and one for hands and controller driven hands. If you want to grab an object using controllers, the object needs a Distance Grab Interactable component, but to grab an object using hands and controller driven hands, the object needs a Distance Hand Grab Interactable component.
- Add a Cube GameObject to your scene by right-clicking in the Hierarchy and selecting 3D Object > Cube.
- Under Hierarchy, select Cube.
- Under Inspector, in the Transform component, set the X, Y, and Z of the Scale property to 0.1.
- In the scene, position Cube so it’s in front of the camera.
- Under Hierarchy, select Cube.
- Under Inspector, add a RigidBody and a Grabbable component.
In the Box Collider component, select the Is Trigger checkbox. This stops the cube from floating away when you release it. Alternatively, you could put Cube on a different Unity layer.
In the Rigidbody component, deselect the Use Gravity checkbox.
Under Hierarchy, select Cube.
- Do one of the following depending on the input method you’re using:
- If you’re using hands or controller driven hands, under Inspector, add a Distance Hand Grab Interactable component.
- If you’re using controllers (not controller driven hands), under Inspector, add a Distance Grab Interactable component.
In the Distance Grab Interactable component or Distance Hand Grab Interactable component, set the Pointable Element and RigidBody properties to Cube.
Select File > Build And Run, or if you have a Link connected, click Play.
When the current scene loads, point your hand or controller towards the cube, and then make a pinching motion with your hands (if using hands) or press the trigger on the controller (if using controllers or controller driven hands). The cube will snap to your hand or controller.
Grabbing a distant object with controllers.
Grabbing a distant object with hands.