Mike Immersed

Rift in Unity Part 2: See Your Hands in VR

September 16, 2018

As I’m developing a VR game in Unity for the Progressive Game Jam at Square One Clubs, I want to share some of the things I’m learning along the way. For now, I’ll be focusing on Oculus Rift support. But I plan to add support and info for other headsets later.

If you want to follow along, you’ll need Oculus Rift + Touch and a computer that meets the Rift system requirements. I’m using Unity 2018.2.8f1.

If you haven’t yet added VR support, follow Part 1 to do so now.

Add the Oculus SDK

In Part 1 we were able to see our scene in VR. But if you tried looking at your hands, they were invisible. Let’s add support for our nifty Touch controllers so we can see our hands and navigate around the scene. To do so, we will need to add additional Oculus assets to the project.

The easy way

The easiest way to add Oculus controller support to a Unity project is to install Oculus Integration from the Unity Asset Store. It just got updated to v1.29. However, sometimes it lags behind the official Oculus SDKs.

  • in your Unity project, open the Asset Store via Ctrl+9 or Window > General > Asset Store
  • in the search bar type “Oculus Integration”
  • select Oculus Integration by Oculus in the search results
  • download (or update) Oculus Integration if necessary

    • click Download (you may have to scroll down)
  • click Import
  • leave all items selected and click Import
  • if prompted, click I made a backup, go ahead (back up your project first if necessary)
  • if prompted to update the Oculus Utilities Plugin, click Yes and click Restart to restart Unity
  • you should now see an Oculus folder under Assets in the Project pane

Oculus Assets

The latest and greatest

But, if the Oculus Integration package isn’t up to date and you want the latest version, the Oculus SDKs can be downloaded directly from Oculus Developer Downloads and imported into Unity. There are three main packages for our purposes:

Add a player controller

Now that we’ve added additional Oculus support, let’s add Oculus’ player controller to the scene. This will replace Unity’s camera and will enable basic navigation.

In the Project pane, expand Assets > Oculus > VR > Prefabs

  • drag OVRPlayerController into the scene
    OVRPlayerController prefab

    • in the Hierarchy pane, expand the OVRPlayerController and select OVRCameraRig
    • in the Inspector pane, change Tracking Origin Type to Floor Level
      Floor Level tracking origin
    • this is based on the floor position from the Rift Configuration
  • delete the Main Camera

Add controller support

Now, we can add an avatar for our player. We will use Oculus’ LocalAvatar prefab to see only our hands. The RemoteAvatar prefab is intended for seeing other visitors’ avatars.

In the Project pane, expand Assets > Oculus > Avatar > Content > Prefabs

  • drag the LocalAvatar prefab into the scene as a child of TrackingSpace (under OVRPlayerController > OVRCameraRig)
    LocalAvatar prefab LocalAvatar child of TrackingSpace

    • it’s important to place it as a child of TrackingSpace so that hands will move properly with the player, head, and hand movements

Add a ground plane to prevent the player from falling and use a cube for reference

  • add a Plane 3D Object to act as the ground so you don’t fall infinitely
    Plane object

    • Position: (0, 0, 0)
    • Scale: (10, 10, 10)
  • also, we’ll keep the cube from part 1 as a reference and set its position to: (0, 0.5, 3)

Try it out

  • press play in Unity, put on your Rift headset and grab your Touch controllers
  • you should be able to move and see your hands, and your fingers should move when you squeeze the grip, squeeze the trigger, or touch buttons on the controllers
  • you can use the thumbsticks to move around the scene and rotate your view

left hand

right hand

Final thoughts

We have now added basic Oculus Touch controller support to our scene including navigation and tracked hands.

Stay tuned, next time we will add the ability to grab an object with our hands.


Mike Henry

Written by Mike Henry, VR enthusiast and software developer. Follow Mike on Twitter