Intro to VR: Setting up XR Origin
Virtual Reality is a technology where people can achieve certain level of immersion inside a computer generated virtual environment or 3D images using devices, such as Oculus Rift, and such. Unity game engine provides different features and API base that is compatible with such device. A developer can easily develop a virtual environment and create interaction between the environment and the devices. To start with the VR development, it is necessary to understand how we set up XR Origin (Action-Based) in Unity.
XR Origin (Action-Based)
XR Origin represents the eyes, ears, and hands of the player or users in the virtual world. It is a game object that allows the movement of the user around the virtual environment to achieve locomotion.
Action-Based: separates logical input from the physical input
STEP 1. From the Unity Package Manager, import two packages:
XR Interaction Toolkit (Also import the Starter Asset that contains all the Sampled Input Actions)
XR Plugin Management
STEP 2. Add XR Origin (Action-Based) game object in the hierarchy. When you add XR Origin, XR Interaction Manager automatically gets added in the project.
Setting the Tracking Origin Mode to Floor
This will represent the tracking origin with the position (0,0,0) as Floor.
Once the game is started, it will include the height of the XR device above the floor.
Setting the Tracking Origin Mode to Device
This mode requires us to specify the offset height of the camera based on the height of the VR user or height of the device above the floor.
STEP 3. Inside XR Origin, there are left hand and right hand controllers. XR Interaction Toolkit package provides the presets to create interaction between the VR environment and UI using their Input Events. We can easily provide these input references to the hand controllers of XR Origin.
Select Right Hand Controller from XR Origin
Go to Inspector Window
Click the preset button next to help button in XR Controller (Action-Based) component.
Select "XRI Default Right Controller" preset.
STEP 4. Set up VR Hands Prefab to the Controller. (Refer to this Section)
STEP 5. Set up Interaction Manager. Add Input Action Manager
In our scene, we now have,
Interactor: Hands
Interactable: would be other GameObjects that our hands can interact with, like grabbing, throwing, etc.
Interaction Manager: that manages interaction between Interactors and Interactables.
Inside XR Origin, we add Input Action Manager and set a reference to XRI Default Input Actions in Action Assets.