Unity VR Basics 2023 – Continuous Movement

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
The reason I’ve decided to change these back is due to the nature of the tutorial here on out. The majority of the tutorials will involve the controllers and will not be XR Hand based. Turning hand tracking off will save power and prevents frame rate loss when testing.

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

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
With this, we will be able to start up the scene and move around using the Left Thumbstick.

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
For this example, we set the two controllers to move the XR Origin based on different settings so we could try our the Dynamic Movement Provider to its fullest extent. When we move forward with our Left Controller, it will move forward based off the orientation of the camera, but with our Right Controller, it will move based off the orientation of the controller.
 
For now, let’s deactivate the Dynamic Move Provider and leave the Continuous Move Provider as Active.

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

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

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)

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)
Now when we move with our headset, it will update the Character Controller as well!