Hello world in Virtual Reality
Tags: beginners, gamedev, vr, virtualreality
Published: 2021-01-16 20:41:44

Note: higer resolution images [here](https://www.notion.so/kauress/Oculus-Quest-2-My-first-Hello-World-in-Virtual-Reality-63d15e33fa074edab880f259af9f7c47)

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](https://dev-to-uploads.s3.amazonaws.com/i/f04zjm6hk3jt9ty0rvbe.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/w0b98d36x62v6wz55rsg.png)

# 1. XR Interaction toolkit

[https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@0.9/manual/index.html](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:
- 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

![Oculus app](https://dev-to-uploads.s3.amazonaws.com/i/12svt21oywo3juols802.jpg)

### ⭐STEP 2: Tap More Settings

- Once connected, click on `More Settings`

![Oculus app](https://dev-to-uploads.s3.amazonaws.com/i/xdjxp6l7qcpn1ioeudef.jpg)

### ⭐STEP 3: Go to Developer Mode

- Now go to `Developer Mode`

![Oculus app](https://dev-to-uploads.s3.amazonaws.com/i/v7todz747unnt8yd0y3w.jpg)

### ⭐STEP 4: Switch on Developer mode

Switch on `Developer Mode`

![Oculus app](https://dev-to-uploads.s3.amazonaws.com/i/ed9s2bbsq03dammh9rw4.jpg)
# 3. Plug Oculus Quest into your PC using the link cable

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0lsq0ealczdcnczffcin.jpg)

1. Go to your Oculus app on your Desktop and follow these steps: [https://support.oculus.com/632287656943461/](https://support.oculus.com/632287656943461/)

# 4. Setting up for VR with Unity3D + Oculus

## ⭐STEP 1: Download plugins

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

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

 2. Go to `Window → Packages` 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6jirm6owwk55qpmzrce6.gif)

3. Download the following packages:

- XR Plugin Management and XR Interaction toolkit

![XR Plugin ](https://dev-to-uploads.s3.amazonaws.com/i/6d2s5xutnasxh3olny92.png)

2. Download Oculus Integration Plugin

![Oculus Integration](https://dev-to-uploads.s3.amazonaws.com/i/i9uo23cvjbk2cmvhq1mp.png)

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

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

![Settings for VR](https://dev-to-uploads.s3.amazonaws.com/i/wgl3hj126yeqzbm0eotd.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/wfw0pj27npo6a1f53328.png)

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

![Settings for VR](https://dev-to-uploads.s3.amazonaws.com/i/oxc12jkfkfqgvya1ityi.png)

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

![Build](https://dev-to-uploads.s3.amazonaws.com/i/nowakqh7n20ev47xs1y6.png)

# **5: Make the game world**

 0. 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](https://dev-to-uploads.s3.amazonaws.com/i/r36ro5m08ru2jdibsc9e.gif)

2. 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](https://dev-to-uploads.s3.amazonaws.com/i/m4ohmsxpiee9zkxqcqsp.png)

3. 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`

4. 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](https://dev-to-uploads.s3.amazonaws.com/i/tuoldygh1caht85u3t8e.gif)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qolfl3107cdifeuf8nxu.png)

6. 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](https://dev-to-uploads.s3.amazonaws.com/i/m0qjeesicb778wjxf8el.gif)

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

8. 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](https://dev-to-uploads.s3.amazonaws.com/i/lv5yg6xulk8fxokm0qxb.png)

# 6: Add Room Scale XR rig

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

1. 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](https://dev-to-uploads.s3.amazonaws.com/i/a09ic4j4lzd9m7ujr4b4.gif)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ttj7k1osjdbwy8knfgl5.png)

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

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lg0kwgtkclavdxhzqcua.png)

4.  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](https://dev-to-uploads.s3.amazonaws.com/i/w8sobexbeudqdu5vhl4v.png)

5. 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](https://dev-to-uploads.s3.amazonaws.com/i/lq6kni26zlum3r9f9id8.jpg)

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

![Oculus quest](https://dev-to-uploads.s3.amazonaws.com/i/guvzetszk6z9kmjtxdvj.jpg)

### ⭐STEP 4: Play your VR experience

[play experience](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/f34e3b2e-b27a-4c25-a277-6448a82d3de1/vrhelloworld.gif?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20210116%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210116T204029Z&X-Amz-Expires=86400&X-Amz-Signature=908550b0bbd6ac24f26c821601fd0e96af612348ec0b84718fd4ded02c114a31&X-Amz-SignedHeaders=host&response-content-disposition=filename%20%3D%22vrhelloworld.gif%22)