Oculus Rift & Unity - Movement Control with the Headset and Touch Controllers. Grabbing action.

in #technology • 7 years ago (edited)

👉 Difficulty


Beginner+

👉 What You Will Learn?


How to enable services for VR headset motion control and Oculus touch controller in UNITY.

👉 Requirements


✔ Basic knowledge about UNITY SDK :

  • Setting up the scene and the base objects
  • Handling the Hierarchy panel
  • Changing Player settings

✔ Oculus Rift with Touch controllers


One of the most important features of VR app is an easy and intuitive way of interaction with the user.

Cover picture Grabbing.jpg

Nowadays market is full of the devices, which allow us to interact with VR world pretty smoothly. They are very various, from the simplest like magnetic button - initially introduced for the earliest version of Google Cardboard, next simple remotes (Daydream, Oculus Remote etc, and many others ‘no-name’ controllers), then game pads and finally dedicated controllers (Oculus touch, HTC Vive controllers or Valve Knukles Cap).

Yet more ergonomic controllers are under development, mostly in the form of gloves or easier to hold and operate touch controllers. I am really looking forward to testing them!

In this article my base will be Oculus Rift with Oculus Touch controllers. We will start from the basics - head movement, then full body movement with controlled for e.g. with pad, to finish with grabbing of the objects. Let’s start then :)

controllers.jpg
Fig.1 [1] Google Cardboard1, [2] 'No-name remotex, [3]Google Daydream3, [4]Xbox Pad4, [5]Oculus Touch5, [6] Oculus Remote6.

➧ USE YOUR HEAD

1. Oculus PlayerSettings.jpg

Fig.2 Oculus Player Settings

Open 'Player' Settings and then in the 'Inspector' panel navigate to 'XR Settings'.
Tick ☑ ‘Virtual Reality Supported’ and if 'Oculus SDK' doesn’t appear add it using (+).

When you will hit play, you will see that you are able to look around. Also if Oculus is set up properly and paired with the sensors, you can move around just by walking. If you intention is to move using the controllers - like a pad, this is not working yet.

Don’t worry It is easy to fix.


➧ MOVE AS A PLAYER

To get this functionality we need to download the following packages:

  • 'Oculus Utilities for Unity' ,
  • 'Oculus Avatar SDK',
  • 'Oculus Platform SDK'.

from https://developer.oculus.com/downloads/

3. Oculus Utilities Import.jpg

Fig.3 Oculus Utilities Import

After downloading and extracting them, import 'OculusUtilities' package to UNITY (double click on a package). Everything will be placed then in the 'OVR' and 'Plugins' folders within your ' Assets' folder.

4n. Assets Oculus Utilities.PNG

Fig.4 Assets Oculus Utilities


Now go to the 'OVR/Prefabs' folder and drag 'OVRPlayerController' prefab to the 'Hierarchy' panel.

prefab.png

Fig.5 Left Hierarchy OVRPlayerController Right Assets OVR Prefabs

Now you should be able to see a physical capsule on the Scene. It represents a player in 3D environment.
For tests purpose lets put predefined UNITY plane under the capsule.

6. Capsule and Plane.PNG

Fig. 6 OVR PlayerController and Plane placement

Hit Play again. Now you are able to move with your controller as well.

➧ GRABBING THE GAME OBJECTS

It is the highest time now to get our virtual hand on the scene.
Import 'OculusPlatform' package and then 'OculusAvatar' package.

8-9.png
Fig.7 Packages Import

You will see that the new folders ‘OculusPlatform’ and ‘OvrAvatar’ were created in your 'Assets' folder.

10.jpg
Fig.8 Created folders

From OvrAvatar/Content/Prefabs drag 'LocalAvatar' to the OVRPlayerControler/OVRCameraRig/TrackingSpace in your 'Hierarchy' panel.

11.jpg
Fig.9 LocalAvatar prefab addition

Now you should be able to see avatar hands and move them. Almost done.
In order to make a try on grabbing something, put a cube or another solid on the scene. You will notice that you can’t grab it yet.

Let’s add 'OVRGrabber' and 'SphereCollider' components to the 'LeftHandAnchor' and 'RightHandAnchor' in OVRPlayerControler/OVRCameraRig/TrackingSpace (visible in 'Hierarchy' panel).

Change 'SphereCollider' component Radius parameter to 0.05 and make sure that 'IsTrigger' parameter is ticked.

In 'OVRGrabber' component go to 'GripTransform' parameter choose LeftHandAnchor for LeftHandAnchor. Increase 'Grab Volumes' size to 1 and drag 'LeftHandAnchor' to the 'Element0' field.
For 'Controller' parameter choose 'L Touch'. Uncheck 'Use Gravity' in a 'Rigidbody' component.

Do the same for the 'RightHandAnchor' but in 'OVRGrabber' component for Controller parameter this time choose 'R Touch'.

Let’s back to our cube. Select it, and in the 'Inspector' panel add new 'OVRGrabbable' component and 'Rigidbody'.


Fig.10 Left and RightHand Anchor properties

Do the same for the 'RightHandAnchor' but in 'OVRGrabber' component for 'Controller' parameter this time choose 'R Touch'.


Let’s back to our cube. Select it and in the 'Inspector' panel add new 'OVRGrabbable' component and 'Rigidbody'.
That's all. Hope you succeed with your own attempts!

All product names, trademarks and registered trademarks are property of their respective owners. All company, product and service names used in this website are for identification and educational purposes only. Use of these names, trademarks and brands does not imply endorsement.

Sources of the pictures and citations:

[X] Own source
[1] https://www.gearbrain.com
[3] https://vr.google.com/daydream/
[4] https://www.xbox.com
[6] https://www.turbosquid.com/

Sort:  

Good job, very clear tutorial!

Congratulations @vrgameprogrammer! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

Are you a DrugWars early adopter? Benvenuto in famiglia!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @vrgameprogrammer! You received a personal award!

Happy Steem Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!