VR is always evolving and changing and it looks like locomotion and continuous movement using the XR Interaction Toolkit has also evolved! Some scripts that we had to write in the previous version of this series are now built into the XR Interaction Toolkit.
Overall, it’s been made a ton easier and accessible. Let’s dive in and get Continuous Movement working!
Changes From Previous Tutorial
If you’re following from the previous XR Hands Tutorial, these are some recommended changes that I’m making to my project.
- Turning off Hand Tracking on Quest 2
- Left/Right Controller -> XR Controller
- Model = Left/Right Hand model from XR Input and Hand animation video
Locomotion System
The first thing we need to add is our Locomotion System. This component will be responsible for handling our different locomotion providers by enforcing only one provider has access to the XR Origin at one time.
- Expand XR Origin
- Create empty game object called ‘Locomotion System’ and select it
- Add Component ‘Locomotion System’
- XR Origin = XR Origin
- Add Component ‘Locomotion System’
- Create empty game object called ‘Locomotion System’ and select it
With that in place, we’re not ready for the Continuous Move Provider.
Continuous Move Provider
In order to move, we need to have a provider that will take user input and communicate with the Locomotion System to move the XR Origin. The first one we’ll cover is the Continuous Move Provider.
- Select the Locomotion System
- Create an Empty Game Object called ‘Move’
- Add Component ‘Continuous Move Provider (Action-based)’
- System = Locomotion System
- Gravity Application Mode = Immediately
- Forward Source = Main Camera
- Left Hand Move Action
- Use Reference = True
- Reference = XRI LeftHand Locomotion/Move
- Add Component ‘Continuous Move Provider (Action-based)’
- Create an Empty Game Object called ‘Move’
If we wanted to move using our Right Thumbstick, we would just have to change the reference to XRI RightHand Locomotion/Move and activate the Right Hand Move Action.
Dynamic Move Provider
A version of action-based continuous movement that automatically controls the frame of reference that determines the forward direction of movement based on user preference for each hand. For example, can configure to use head relative movement for the left hand and controller relative movement for the right hand.
- Select ‘Move’ game object
- Add Component ‘Dynamic Move Provider’
- System = Locomotion System
- Forward Source = Main Camera
- Left Hand Move Action
- Use Reference = True
- Reference = XRI LeftHand Locomotion/Move
- Right Hand Move Action
- Use Reference = True
- Reference = XRI RightHand Locomotion/Move
- Head Transform = Main Camera
- Left Controller Transform = LeftHand Controller
- Right Controller Transform = RightHand Controller
- Left Hand Movement Direction = Head Relative
- Right Hand Movement Direction = Hand Relative
- Add Component ‘Dynamic Move Provider’
Continuous and Snap Turn Provider
Turning is just as important as moving forward and backwards, so let’s add that! We can either choose continuous and snap turn. Continuous has been known to cause some VR Sickness, so keep that in mind when adding it to your games.
- Select Locomotion System
- Create empty game object called ‘Turn’
- Add Component ‘Continuous Move Provider (Action-based)’
- Locomotion System = Locomotion System
- Right Hand Turn Action
- Use Reference = True
- Reference = XRI Right Hand Locomotion/Turn
- Add Component ‘Continuous Move Provider (Action-based)’
- Create empty game object called ‘Turn’
If we start up the Scene now, we’ll be able to use the Left Hand Controller to move and the Right Hand controller to Turn.
Let’s turn off the Continuous Move Provider and add a Snap Turn Provider.
- Select ‘Turn’
- Add Component ‘Snap Turn Provider (Action-based)’
- Locomotion System = Locomotion System
- Right Hand Turn Action
- Use Reference = True
- Reference = XRI Right Hand Locomotion/Snap Turn
- Add Component ‘Snap Turn Provider (Action-based)’
Now when we start up the Scene, it will snap and turn whenever we hit the right or left on our Thumbsticks.
Character Controller
One last thing we should add is a Character Controller. This will allow us to stop ourselves from walking through objects.
- Select the XR Origin
- Add Component ‘Character Controller’
- Radius = 0.2
- Center = (0, 1, 0)
- Add Component ‘Character Controller’
Now when we walk off the edge with gravity or into a wall, we’ll fall off or we will be stopped by the wall!
The only problem is that whenever we move our head mounted display independent from moving using the thumbstick, it won’t update our character controller. To fix this, we need to add a Character Controller Driver.
- Select XR Origin
- Add Component ‘Character Controller Driver’
- Locomotion Provider = Move (Action Based Continuous Move Provider)
- Add Component ‘Character Controller Driver’