Unity VR : Swapping Teleportation and Continuous MOvement

It’s time we cover how to switch between the different movement systems. In most VR games, you can choose between Continuous Movement and Teleportation. It’s always a good idea to give players both options. Some users suffer from motion sickness  while others won’t, but may prefer the immersion given by Continuous Movement.

In this tutorial we’ll learn how to switch between Continuous Movement and Teleportation. We’ll start by improving our teleportation from the previous teleporting video, then we’ll learn how to use a ui dropdown menu to swap between teleporting and continuous movement and last we will use a Locomotion Manager to connect it all together.

To follow along, download the Github project found here.

1 : Scene Review

Opening up the scene, we will be greeted by this!

A canvas and some ui that says “Movement Type” as well as a plane on the ground for teleporting. Oh! and the pink table is there… as always!

 

2 : Improving our teleport

It turns out our teleport from the previous tutorial, found here, has a bit of a bug in it. It allows for teleportation to areas that are not teleportation areas. If you were making a game, this would be a major hiccup since your players could go wherever they’d like.

If you go to project -> scripts -> 12 swapping teleportation and continuous movement, then open  TeleportationControllerFixed, you’ll be greeted with this.

I haven’t highlighted the entire script since we went through it in my teleportation tutorial, but I have highlighted the one major change added. The 5th ‘if’ statement will check for a tag called “Teleport”. If the raycast target that we hit has that tag, then we’ll be able to teleport!

With that small change, our teleport should work correctly! All we need to do is add the tag “Teleport” to our teleportation area and it should work.

Go back to the Editor and select the Teleportation Area in the Scene. Locate the Tag dropdown at the very top of the inspector and add the “Teleport” tag.

Now if you start up the scene, you should be able to teleport around correctly!

3 : Adding a Dropdown Menu

Now that our teleport is fixed, let’s add a drop down menu to the UI.

  •  Select the MovementCanvas in the Scene
    •  Right click and go to UI -> Dropdown-TextMeshPro
    • Select the created Dropdown menu
      • Select the Anchor square in the top right of the Rect Transform, then hold shift + alt and select the box 4 rows down and 3 columns over.
      •  Pos X = -2
      • Scale = ( .08, .08, 1)
      • Locate the Dropdown – TextMeshPro component and then locate where is says Options.
        • Change Option A to “Continuous Movement”
        • Change Option B to “Teleport”
        • Select to highlight Option C and then hit the minus sign to delete it.
      •  Expand Dropdown and select the child called Label.
        • Locate TextMeshPro – Text(UI) and check the box called Auto Size.
        • Set Auto Size Options Min to 10.
Now we should have something that looks like this!
 

The drop menu is in place, it is time that we combine it with our movement system in order to allow switching.

4 : The Locomotion Manager

We already have a Locomotion System in our Scene, but we have nothing to manage it. What we need is a script that allows the swapping of the Teleportation Provider or Continuous Move Provider scripts. Luckily, I have already created one!

  • Select Locomotion System and 
    • Add a component script called Locomotion Manager.
    • Add the Left Ray Teleport and Right Ray Teleport to the empty slots located on the Locomotion Manager.

Lets double click the Locomotion Manager and go over what it does.

We start off by importing the XR Interaction Toolkit so we can use the scripts that we’ll need later. We have to public GameObjects that will hold our left/right ray Teleports that will need to be set to inactive if we are not using the teleport. We also have two private variables for the Teleportation Provider script and Continuous Move Provider script. 

The Start function simply goes out and grabs these scripts since they are located on our Locomotion System.

We also have a public function called SwitchLocomotion. It takes an integer and will switch the between continuous move and teleport based on the value passed in. Now if we remember, the dropdown menu has it’s first value as “Continuous Move” and second value as “Teleport”. These values are represented with 0 and 1 based on their positioning in the list. When we connect this script to the dropdown menu, the dropdown menu will send a value of 0 or 1 to this function so we can switch between the teleporting and continuous movement.

The rest of the script are very simple functions that enable/disable the teleport/continuous providers as well as other gameobjects associated with those systems.

5 : connecting our dropdown menu

The last thing we need to do is connect our dropdown menu and our Locomotion Manager script.

  • Expand MovementCanvas and select Dropdown.
    •  Navigate to Dropdown – TextMeshPro and find the On Value Changed at the bottom.
      • Click the plus sign
      • Drag the Locomotion System into the empty slot.
      • Click the dropdown where is says “No Function” and go to LocomotionManager -> (Dynamic int) Switch Locomotion.

Make a special note here to use the Dynamic int version of Switch Locomotion. If you don’t, it will not dynamically change when we use the dropdown in game.

With that, we’re all done! We can start up the Scene now and use the dropdown to swap our types of movement!

6 : Conclusion!

That’s it! We can now swap between the different modes of movement within VR! 

If you’d like a challenge, try to scale down the UI and mount it to you wrist like we did in the previous tutorial found here!

1 thought on “Unity VR : Swapping Teleportation and Continuous MOvement”

Comments are closed.