Unity VR : Continuous Movement

Unity VR : Continuous Movement

This week we’re diving into more movement! We’ll be covering how to implement Continuous Movement so our players aren’t stuck teleporting as their only option.

To follow along, you can find the Github project here.

In this tutorial, we’ll learn how to setup a locomotion system, how to implement Snap and Continuous turning, how to create a Continuous Move Provider, and how to apply a Character Controller to our XR Origin.

1 : Scene Review

We’ve kept the ball and table to interact with in the center of the Scene. We also have our Ray Interactors from before since we aren’t using rays to teleport. I’ve also added a ramp for us to climb up once we get our continuous move working.

2 : Locomotion System

Like in our previous tutorial, we start by making a locomotion system.

  • Right click in the Scene and go to XR -> Locomotion System (Action Based).
  • Select the Locomotion System, locate the Locomotion System script and drag the XR Origin into the empty slot.
  • Select the Locomotion System, locate the Snap Turn Provider and check the box for Right Hand Snap Turn Action “Use Reference”.
  • In the empty Reference slot, add XRI RigthHand/Turn.
Attributes
  • System –  This is a reference to the Locomotion System used to turn the player
  • Turn Amount-  Used to determine the degree in which the player turns when the control is pressed.
  • Debounce Time – The time between a player turning and when a turn event on the controller should trigger another turn.
  • Enable Turn Left Right –  Allows player to turn left and right.
  • Enable Turn Around –  Allows player to turn in a 180 if the thumbstick is pulled back.
  • Left/Right Hand Turn Action – Can be enabled to allow for turning with the left/right hand controller. 
  • Reference – Uses right/left hand input references to determine what Action will be used for turning.

With that, we should be able to Snap Turn using our right analog stick. This is a great solution for people who suffer from VR/motion sickness. When I first tried out VR, snap turn was the only option for me until I got my VR legs.

3 : Continuous Turn

If you want to give the player a more fluid turning experience, then Continuous Turn is the way to go.

  • Select Locomotion System and click Add Component.
  • Add a Continuous Turn Provider (Action-based).
  • Locate the Continuous Turn Provider and check the box for Right Hand Snap Turn Action “Use Reference”.
  • In the empty Reference slot, add XRI RigthHand/Turn.
  • Locate the Snap Turn Provider and disable it by checking the box next to its name. 
Attributes
  • System –  This is a reference to the Locomotion System used to turn the player
  • Turn Speed –  Can be adjusted to allow for quicker or slower turning.
  • Left/Right Hand Turn Action – Can be enabled to allow for turning with the left/right hand controller. 
  • Reference – Uses right/left hand input references to determine what Action will be used for turning.

The reason we disable the Snap Turn Provider is to prevent any errors from having two systems trying to turn our player at the same time. If you start up the scene now, you should be able to turn continuously. 

So which one should we use? Well variety is the spice of life, and in this case, it’s more of the quality of life for our player. When setting up play options, I’d advise leaving both these as options for your player and allowing them to select between the two. Just deactivate or activate them based on what they choose in the menu system you set up.  

4 : Continuous Move

Let’s get our Continuous Move up and running!

  • Select the Locomotion System and click Add Component.
  • Add a Continuous Move Provider (Action-based)
  • Locate the empty System slot and add our Locomotion System to it.
  • Check the Left Hand Move Action
  • Locate the Reference empty slot and add the XRI LeftHand/Move to it
Attributes
  • System –  This is a reference to the Locomotion System used to turn the player.
  • Move Speed – Variable allowing for move speed to be increased or decreased.
  • Enable Strafe – Allows player to perform sideways movement.
  • Gravity Application Mode –  Either set to Attempting Move or Immediately. Attempting Move will only apply physics when the player has moved and will continue until they are touching the ground. Immediately will apply physics every frame.
  • Forward Source –  The transform to be used to determine what is considered forward.
  • Left/Right Hand Turn Action – Can be enabled to allow for turning with the left/right hand controller. 
  • Reference – Uses right/left hand input references to determine what Action will be used for turning.

Notice that we left movement for our left hand. Since we are using our right hand to turn, it will prevent unwanted behavior separating these controls. If you prefer it the other way around, go for it!

We still need to add two more components to get our continuous move to work.

  • Select the XR Origin and click Add Component.
  • Add a Character Controller.
  • Change the Center to (0, 1, 0)
  • Change the Radius to 0.3
  • Click Add Component and add a Character Controller Driver
  • Set the Locomotion Provider to our Locomotion System
  • Set the Min Height to 1
  • Set Max Height to 2

The Character Controller will be what we can use to determine the colliders for our player. One thing worth mentioning is that it doesn’t update the collider unless we are moving with the analog stick. If we just move our head, the collider will remain in place. It may cause some unwanted behavior, but the trade off is that it isn’t updating every frame and taking valuable processing power. 

The Character Controller Driver is also important. We set the Min and Max Height for our player here to prevent them from shrinking down to much or from being too high up.

Conclusion!

That’s all there is to it for Continuous Move. There are plenty of attributes to tweak and play with to make sure you create the right game feel for your player. 

Thanks for reading and see you in the next one!