DEV Community

Cover image for Hello world in Virtual Reality
Kauress
Kauress

Posted on

Hello world in Virtual Reality

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

![pic](Alt Text

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

![setting up](Alt Text

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?

  1. 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
  2. The XR interaction Toolkit is available as a package that is available from Unity3D's package manager
  3. 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
  4. Some of these cross-platform XR components are:
  5. XR controllers: left and right controllers
  6. 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
  7. XR interactables: These are objects that an interactor can interact with. For example Grabbing, pushing , pulling
  8. XR interactors:These components handle actions such as hovering over an object and selecting objects
  9. Gestures: these are gestures such as swiping, pinching
  10. Interaction manager: Responsible for sending information between the interactable and interactor
  11. XRUI input module: allows you to capture input from XR devices such as the Oculus Quest
  12. Tracked device graphic raycaster: Allows you to select UI components in 3D example buttons
  13. 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

Oculus app

⭐STEP 2: Tap More Settings

  • Once connected, click on More Settings

Oculus app

⭐STEP 3: Go to Developer Mode

  • Now go to Developer Mode

Oculus app

⭐STEP 4: Switch on Developer mode

Switch on Developer Mode

Oculus app

3. Plug Oculus Quest into your PC using the link cable

Alt Text

  1. 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

  1. Now we will be downloading the 3 plugins that we need for our project

  2. Make a new Unity3D project and save it in the drive of your choice

  3. Go to Window → Packages

Alt Text

  1. Download the following packages:
  • XR Plugin Management and XR Interaction toolkit

XR Plugin

  1. Download Oculus Integration Plugin

Oculus Integration

  1. In File → Build Settings → add the current scene to Build → Run Device and choose your Oculus Device → Build

  2. Change Graphic API. Go to File → Build Settings → Player Settings → Player → Graphic Apis and drag OpenGLES3 to the top

Settings for VR

5.Go to File → Build Settings → Player Settings → Player → Minimum APILevel and change the APILevel so that it is 23 or higher

Settings for VR

  1. Choose Oculus under XR plugin Management in the Player settings

Settings for VR

  1. Choose the current scene to Build, make sure your Oculus is plugged in and under Run Device choose your Device

Build

5: Make the game world

  1. 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

    1. 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

Game world

  1. Change the position of the plane that we just added to x: 0, y : 0 and z : 0 in the Inspector Window to the right. Also change the name to Ground or Floor

Alt Text

  1. Now let's add some color to our Ground . Make a folder called Materials inside the main Assets folder. Right click on Assets → Create → Folder Rename the folder as Material

  2. 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 as Ground.

Alt Text

  1. Click on Ground and from the right side in the Inspector window choose a color of your liking from the color wheel

Alt Text

  1. 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

Alt Text

  1. 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

  2. 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 the Inspector window to the right. Make sure it is selected first

Alt Text

6: Add Room Scale XR rig

  1. 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.

  2. 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

Alt Text

  1. With the Room-Scale Rig selected on the right in the Hierarchy window you can see where it is on your plane

Alt Text

  1. The XR Interaction Manager and Event System are added to the Hierarchy window when you add the Room-Scale XR Rig

Alt Text

  1. In the Hierarchy window if you click on dropdown icon of Room-Scale XR Rig → Camera Offset You will see the Main Camera, Left-Hand Controller and Right-Hand Controller components. We don't need to change anything there. The Tracked Pose Component inside the Main 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

Alt Text

  1. Save your game by clicking on File → Save or CTRL + S

6: Inside Oculus Quest 2

⭐STEP 1: Go to the Oculus Quest Dashboard and click on the icon

Oculus quest

⭐STEP 2: Select Unknown Sources and select your VR experience from the menu

Oculus quest

⭐STEP 4: Play your VR experience

play experience

Oldest comments (1)

Collapse
 
grigorirena profile image
Irena Grigor

I already have experience with Unity3D, so I'm looking forward to trying to create a virtual reality program using the Oculus headset.