Note: higer resolution images here
This tutorial will guide you through creating your first program in VR. This tutorial uses the following hardware:
- Oculus headset.
- In addition you must have the windows OS running
- a PC strong enough to handle VR
- Oculus link cable (you can also use the Oculus charger however, it is much slower)
Note: You can get a USB-C to USB-A converter if need be
Software requirements:
- Unity3D version 2019.3.11f1 and above
Note: Make sure that the Android Build Support
module is included in your installation. If it is you will see the Android icon.
Note: Oculus is an android device
If not then you can add it by clicking on the 3 ...
dots to the upper right corner of the dialogue box and then Add module → Android Build Support
1. XR Interaction toolkit
https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@0.9/manual/index.html
Introduction
In order to build VR experiences quickly and easily it is advised to use the XR Interaction Toolkit which allows you to handle basic VR capabilities such as grabbing objects, locomotion, gestures, pushing, pulling and more. This makes your workflow faster as you do not now have to code common everyday functionalities from scratch and can instead focus on coding functionalities that are unique to your game/experience.
What is it and what does it do?
- The XR interaction toolkit is a framework that allows you to build cross-platform AR and VR experiences. It simplifies interactions in VR by allowing plug-n-play functionality. This allows developers,designers and novices to build AR and VR experiences more easily
- The XR interaction Toolkit is available as a package that is available from Unity3D's package manager
- Once you download the toolkit you will see the XR Plugin Management component this will allow you to add and manage more plugins such as the Oculus XR plugin, ARCore plugin etc
- Some of these cross-platform XR components are:
- XR controllers: left and right controllers
- XR rig: This represents the player, provides room scale tacking. It allows you to move around a room, look around the world, look at the controllers in 3D an so on
- XR interactables: These are objects that an interactor can interact with. For example Grabbing, pushing , pulling
- XR interactors:These components handle actions such as hovering over an object and selecting objects
- Gestures: these are gestures such as swiping, pinching
- Interaction manager: Responsible for sending information between the interactable and interactor
- XRUI input module: allows you to capture input from XR devices such as the Oculus Quest
- Tracked device graphic raycaster: Allows you to select UI components in 3D example buttons
- AR components: AR interactables and interactors
2. Setting up the Oculus Quest app
⭐STEP 1: Download the Oculus app and connect your Oculus Quest 2
- Download the Oculus phone app. Switch on your bluetooth. In your app connect your Oculus
⭐STEP 2: Tap More Settings
- Once connected, click on
More Settings
⭐STEP 3: Go to Developer Mode
- Now go to
Developer Mode
⭐STEP 4: Switch on Developer mode
Switch on Developer Mode
3. Plug Oculus Quest into your PC using the link cable
- Go to your Oculus app on your Desktop and follow these steps: https://support.oculus.com/632287656943461/
4. Setting up for VR with Unity3D + Oculus
⭐STEP 1: Download plugins
Now we will be downloading the 3 plugins that we need for our project
Make a new Unity3D project and save it in the drive of your choice
Go to
Window → Packages
- Download the following packages:
- XR Plugin Management and XR Interaction toolkit
- Download Oculus Integration Plugin
In
File → Build Settings → add the current scene to Build → Run Device and choose your Oculus Device → Build
Change Graphic API. Go to
File → Build Settings → Player Settings → Player → Graphic Apis
and dragOpenGLES3
to the top
5.Go to File → Build Settings → Player Settings → Player → Minimum APILevel
and change the APILevel
so that it is 23
or higher
- Choose Oculus under XR plugin Management in the Player settings
- Choose the current scene to Build, make sure your Oculus is plugged in and under Run Device choose your Device
5: Make the game world
-
Now let's go ahead and make the game work for our first Hello World experience in VR. If you don't have any Unity3D experience don't worry we will start from scratch
- Let's create the ground for our game world. Just like we have the ground on which we stand on, the same way let's create a ground for our VR world. To do this click on
GameObject → 3D Object → Plane
This will create a plane in our scene. You can adjust the scale of the plane within the Inspector window to the right
- Let's create the ground for our game world. Just like we have the ground on which we stand on, the same way let's create a ground for our VR world. To do this click on
- Change the position of the plane that we just added to
x: 0, y : 0 and z : 0
in theInspector Window
to the right. Also change the name toGround
orFloor
Now let's add some color to our
Ground
. Make a folder calledMaterials
inside the mainAssets
folder.Right click on Assets → Create → Folder
Rename the folder asMaterial
Double click on the Materials folder to open it and now create a new material by Right clicking inside the
Material folder → Create → Material
. Rename the newly created material asGround
.
- Click on
Ground
and from the right side in the Inspector window choose a color of your liking from the color wheel
- Now let's apply the Ground material to the 3D Ground object in the scene. By Clicking on it and dragging it onto the Ground 3D plane object
Now go ahead and add some more 3D objects onto the ground such as cubes and spheres. And then within the Material folder create some materials to apply on your 3D objects. You will be repeating steps
1, 2, 5 and 6
You can create the Hello World text the same ways as you created other 3D objects. Go to
GameObject in the menu bar → 3D Object → 3D Text
. You can play around with it's position settings in theInspector window
to the right. Make sure it is selected first
6: Add Room Scale XR rig
In this part we will be adding a room scale XR rig. The Room-Scale XR Rig will allow you to move around in VR as though you were in a room.
To do that
right click anywhere in the empty space in the Hierarchy window and then click on Xr and then Room-Scale XR Rig
- With the Room-Scale Rig selected on the right in the Hierarchy window you can see where it is on your plane
- The
XR Interaction Manager
andEvent System
are added to theHierarchy window
when you add theRoom-Scale XR Rig
- In the
Hierarchy window
if youclick on dropdown icon of Room-Scale XR Rig → Camera Offset
You will see theMain Camera
,Left-Hand Controller
andRight-Hand Controller
components. We don't need to change anything there. TheTracked Pose Component
inside theMain Camera
component will get information about your pose from Oculus and be tracking your eyes as you move around the game world and changing the view of the world accordingly
- Save your game by clicking on
File → Save
orCTRL + S
Top comments (1)
I already have experience with Unity3D, so I'm looking forward to trying to create a virtual reality program using the Oculus headset.