Virtual Reality in Unity
Game engine: Unity; VR headset: 3 DOF or 6 DOF; SDK: Unity XR plugin framework
- Download unity-hub from here
- Open unity hub and select add unity version from top right
- Select the options for build support as shown below
- Agree to terms and conditions and hit Done.
5. Select universal renderer pipeline, enter project name, location and hit Create.
6. Make sure VR headset is working by enabling unknown sources as shown below.
7. Creating project opens unity where different windows can be seen
8. Scene window, Render window, Hierarchy, Inspector tab, Project window
9. In projects window → Scenes → Right click, create new scene.
10. To setup VR, goto Window → Package Manager → Search for XR interaction tool kit.
11. If not shown, goto Advanced option, then select XR interaction tool kit.
12. To select device, goto Edit → Project Settings → XR plugin management → Install XR plugin management
13. Select one or more devices
Creating actual game
Create ground for game
- Hierarchy → Right click → Plane
- Position it to centre (0,0,0) and scale it. Add colour as black material
- Delete main camera
- Create a new empty game object and position it to (0,0,0)
- Add new XR rig component
6. Create camera offset as child of VR Rig component. Create Camera as child of camera offset.
7. Add another component Tracked Pose Driver
8. Drag camera offset and camera to camera floor offset and camera game object as shown below. Change tracking origin mode to Floor. Change VR Camera → Projection → Near to 0.1
We can see the scene moves as head moves!
9. To control hand movements, add two new objects one for left hand and other for right hand
10. Select both and add component → XR Controller
11. Add prefab to Model Prefab for both hands
12. Create objects to grab. For that, add XR Grab Intractable component for the created object. Say a rigid body sphere.
13. Set XR Direct Interactor component for left and right hands.