© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
C. CoutinhoUnity® Virtual Reality Development with VRTK4https://doi.org/10.1007/978-1-4842-7933-5_9

9. Moving Around the Virtual World: Teleportation

Christopher Coutinho1  
(1)
GameWorks, Mumbai, Maharashtra, India
 

The ability to move within the virtual world is an essential part of any VR experience. In this chapter, you’ll learn how to get yourself moving in the virtual world. We’ll begin by implementing a commonly employed movement scheme referred to as teleportation. Teleportation is not the only way to move around in your virtual world, though; the VRTK provides you with quite a few alternatives for movement, which we’ll look at in upcoming chapters. VR movement, or locomotion, as it’s commonly referred to, can assume many forms, and the VRTK provides you with a surfeit of mechanics when it comes to locomotion. Some of the different options available include teleportation, free movement, arm-swinging locomotion, and hulk style movement, as well as being allowed to walk to where you want to go in the virtual world, while being physically constrained to the boundaries of your Guardian or Chaperone. Some forms of locomotion, primarily free movement and rotation, may cause nausea if you aren’t used to performing them in a VR setting. If you start to feel any discomfort, take a break and get some fresh air.

In this chapter, you’ll learn to implement the three forms of teleportation that the VRTK provides: Instant Teleport, Dash Teleport, and Teleport Targets, which all cover long distances. You’ll learn how to set up an arrow pointer on your controllers that you can use to rotate yourself in the virtual world. You’ll finally learn how to set up a Unity NavMesh for Teleportation.

Teleport Locomotion

The main reason why teleportation is so prevalent in VR is that it helps avoid motion sickness. Motion sickness occurs when there’s a mismatch between what you see and what you feel. Teleportation allows you to move the user from place to place rather than having them move smoothly within the virtual world. Teleportation may break the illusion of immersion, but at the same time, it entirely avoids motion sickness, as it doesn’t create a sense of motion at all. If the illusion of immersive movement is not a priority, then the teleport form of locomotion is ideal. For example, it could be used in a VR history museum setting to allow users to teleport from artifact to artifact.

Before we begin setting up teleportation using the VRTK, let’s look at how it works. When you press the designated teleport button on your VR controller, a ray-cast is fired from your head or hand until it either collides with an object that you can teleport against or reaches its desired distance. If the layer for your teleport area (Floor) has been set up for teleportation, the VRTK’s teleport pointer turns green, indicating that a teleporting movement is possible. However, if no valid area for teleportation can be found, the VRTK’s teleport pointer will stay red, indicating that a teleporting movement can’t happen. When you release the designated teleport button, depending on when you want the teleportation to occur, you’ll be repositioned at the point where the ray-cast collided if a valid teleport area is found.

Capturing Inputs to Trigger Teleportation

In Chapter 6, we went over how to set up several intermediary game objects—namely, the Left-Hand Grab and Right-Hand Grab—-into which varied device inputs involved with a left- or right-hand grab action could be channeled. We also consolidated input for either a Right or Left Thumbstick press into two intermediary game objects: Right-Hand Thumbstick Press and Left-Hand Thumbstick Press. All the above intermediary game objects reside in the Button Input Actions game object. Any game object interested in listening for these button actions could then poll these intermediary game objects. This section will use this same approach to channel input actions that trigger a teleport into an intermediary game object.

A teleport can be triggered in one of four ways: by pressing the T key on the keyboard, by pressing the Left Thumbstick button on the Oculus controller, by pressing the Left Trackpad button on the HTC Vive controller, and by pressing the Left Thumbstick button on the Xbox controller. Each of these four input actions need to be channeled into an intermediary game object.

Let’s begin by setting up an intermediary game object into which to channel these input actions. In the hierarchy, select and expand the Button Input Actions game object. Create a new empty game object within it and rename it “Curved Teleport Ray Pointer.” With this game object selected in the hierarchy, click the Add Component button in the Inspector. Add a Boolean Action component to this game object. With the Boolean Action component expanded, locate the Sources property and set its size to 4. Four element slots will be made available and you will have four input actions that you need to listen for.

As you probably noted in Chapter 6, the VRTK doesn’t provide you with an out-of-the-box prefab to capture keyboard input for every key on your keyboard. You need to set this up, just as you did for capturing input for the Q and P keys in Chapter 6. Here you will capture input when the T key is pressed.

Select the VRTK Input Controllers game object from within the hierarchy and expand its Keyboard Input child game object. Select the Input Unity Input Manager Button Action P game object in the hierarchy and duplicate it. Rename the copied game object “Input Unity Input Manager Button Action T.” With this game object selected in the hierarchy, locate its Key Code property in the Inspector, and in the drop-down, select the letter T. The input mapping for the T key will now allow you to listen for a T key press on the keyboard. You could capture several key presses using this procedure.

Now, let’s begin hooking up all input actions to trigger a teleport into the Curved Teleport Ray Pointer intermediary game object by following these steps:
  1. 1.

    From within the hierarchy, with the VRTK Input Controllers game object expanded, ensure that the Keyboard Input game object has been expanded.

     
  2. 2.

    Expand the Input, Unity Input Manager, Oculus Touch Left Controller game object. Then expand its Input Actions game object, followed by expanding its Left Thumbstick game object.

     
  3. 3.

    Expand the Input, Unity Input Manager, Open VR Left Controller game object. Then expand its Input Actions game object, followed by expanding its Left Trackpad game object.

     
  4. 4.

    Finally, expand the Input, Unity Input Manager, X-Box Controller game object. Then expand its Input Actions game object, followed by expanding its Left Thumbstick game object.

     
With these input sources expanded, let’s now capture input for when the left-hand Thumbstick or the T key is pressed. Select the Curved Teleport Ray Pointer game object from within the hierarchy, a child of the Button Input Actions game object. Note that your Boolean Action Sources property has four element slots in the Inspector, as shown in Figure 9-1. Now follow these steps:
  1. 1.

    From within the expanded Input, Unity Input Manager, Oculus Touch Left Controller game object, drag and drop the Left Thumbstick Press [8] game object into the Element 0 slot of the Sources property, as shown in Figure 9-1.

     
  2. 2.

    From within the expanded Input, Unity Input Manager, Open VR Left Controller game object, drag and drop the Left Trackpad Press [8] game object into the Element 1 slot of the Sources property, as shown in Figure 9-1.

     
  3. 3.

    From within the expanded Input, Unity Input Manager, X-Box Controller game object, drag and drop the Left Thumbstick Press [8] game object into the Element 2 slot of the Sources property, as shown in Figure 9-1.

     
  4. 4.

    From within the expanded Keyboard Input game object, drag and drop the Input, Unity Input manager, Button action T game object into the Element 3 slot of the Sources property, as shown in Figure 9-1.

     
Figure 9-1

Hooking up Left Thumbstick and T Key (press) inputs to the Curved Teleport Ray Pointer intermediary game object

Setting Up a Curved Teleport Pointer

One of the prerequisites for implementing teleportation is having a pointer in the scene. The Curved Pointer, also known as a Bezier Pointer , casts a curved beam from an origin point a certain distance into the world and then down, until it collides with a collider. As this curved beam almost always collides with the Floor, the Curved Pointer has become a popular choice when implementing teleport locomotion.

First, let’s set up this Curved Pointer. In the hierarchy, select the VRTK SETUP game object and create an empty child game object within it. Rename this child game object “VRTK RAY POINTERS.” All your pointers, curved or straight, will reside here. This will allow you to locate them quickly.

Select the Project tab and expand the “Packages” folder. Locate the “Tilia Indicators , Object Pointers, Unity folder” and expand it until you reach its “Prefabs” folder. Select the “Prefabs” folder, and from the pane on the right, drag and drop the Indicators, Object Pointers, Curved prefab onto the VRTK RAY POINTERS game object in the hierarchy. You have now set up your first curved pointer as a child of the VRTK RAY POINTERS game object. Select this curved pointer and rename it “Layer Teleport Curved Pointer” to indicate that it will allow teleportation anywhere within a valid Teleport Layer in your virtual world.

There are two ways you can teleport about in your virtual world: first, by teleporting onto any object that has been assigned a valid Teleport Layer, and second, by using explicitly defined Teleport Targets, as will be seen in a later section (Teleporting using Teleport Targets) of this chapter.

With the Layer Teleport Curved Pointer game object selected in the hierarchy, look at the Inspector and ensure that its Pointer Facade component has been expanded. Locate the Follow Source property in the Pointer Settings section of the Pointer Facade component . It’s this property that determines which game object the teleport ray should originate from. If you want your Layer Teleport Curved Pointer to originate from your Left Controller, then drag and drop the Left Controller Alias game object into this Follow Source property. If you want your Layer Teleport Curved Pointer to originate from your Right Controller, then drag and drop the Right Controller Alias game object into this Follow Source property.

Throughout this book, you’ll have all your curved teleport pointers originate from your Headset. In many scenarios, it is preferable to allow players to select the area to which to teleport using their head rather than their hands. For example, in a VR FPS (First Person Shooter), when you’re dual-wielding guns, you wouldn’t want to aim the gun at the Floor just so that you can teleport.

In the hierarchy, expand the VRTK CAMERA RIGS SETUP game object. Then expand its Camera Rigs, Tracked Alias game object and drag and drop the Headset Alias game object into the Follow Source property. Your Layer Teleport Curved Pointer will be deactivated by default.

The Activation Action Property in the Pointer Settings section accepts a Boolean action. It will be responsible for activating and deactivating your Layer Teleport Curved Pointer. When the Activation Action property emits a True value, your Layer Teleport Curved Pointer will be activated, and when it emits a False value, the pointer will be deactivated.

The Curved Teleport Ray Pointer intermediary game object you set up in the previous section has been fitted with a Boolean Action component. All button actions that need to display the Layer Teleport Curved Pointer have been channeled into this game object. It is a perfect fit for your Activation Action property, as it contains the Boolean Action component that your Activation Action property desires. As soon as one of the button actions being listened for is triggered in the intermediary Curved Teleport Ray Pointer game object, its value will be passed to the Activation Action property, and if True, the Layer Teleport Curved Pointer will be displayed.

Now, drag and drop the Curved Teleport Ray Pointer intermediary game object into this Activation Action Property. Figure 9-2 displays this setup so far.
Figure 9-2

The Layer Teleport Curved Pointer game object setup so far

The Activation Action property you hooked up is only responsible for enabling the Layer Teleport Curved Pointer. It won’t physically teleport the player to a new location. The Selection Action property , in conjunction with the Selection Method property, ensures that the player is teleported to the new location once a True value is emitted.

The Selection Action property needs to be provided with a well-defined set of button actions. When any of these button actions are triggered, the player will be physically teleported to the new location. You already have a well-defined set of button actions in the Curved Teleport Ray Pointer intermediary game object. You’ll assign this intermediary game object to the Selection Action property. The moment a button action being listened for in the Curved Teleport Ray Pointer intermediary game object is triggered, your Selection Action property will emit a True value, resulting in the player being teleported to the new location.

You may have noticed that the Curved Teleport Ray Pointer intermediary game object serves two purposes. First, it enables the Layer Teleport Curved Pointer when the Activation Action property emits a True value. Second, it physically teleports the player to the new location when the Selection Action property is True. Both of these properties can be seen in Figure 9-2.

So far, you’ve displayed your Layer Teleport Curved Pointer and ensured that the player is physically teleported to the new location. Now, you need to decide when the actual teleport should take place. You’ll use the Selection Method property to make this decision.

You could have the physical teleport occur as soon as your controller’s Left Thumbstick button is pressed. In this case, your Layer Teleport Curved Pointer would be enabled and you’d be immediately teleported to whichever point the Layer Teleport Curved Pointer is pointing at when the Left Thumb Stick button is pressed. This wouldn’t allow you even a split second to decide where you want to teleport to, so this setup won’t work.

To set up a working teleport, you’ll need to ensure that the physical teleport occurs not when pressing down on your Left Thumbstick button or the T key, but rather when you release either of these components. The moment you press down on either of them, your Layer Teleport Curved Pointer will be displayed. So long as you don’t release the Thumbstick button or the T key, the pointer emitting from your headset will be continually displayed, allowing you to move your head about and point to a precise location where you want to teleport. The moment you release either of these features, you’ll be immediately teleported to the location your Layer Teleport Curved Pointer is pointing. This is a very subtle change that you need to comprehend.

Let’s begin setting this up now on the Layer Teleport Curved Pointer. Ensure that you’ve selected the Layer Teleport Curved Pointer game object in the hierarchy. Drag and drop the Curved Teleport Ray Pointer intermediary game object into the text box of the Selection Action property . Then, set the Value for the Selection Method property to Select on Deactivate to indicate that you want the physical teleport to occur only when the Left Thumbstick or T key is released. Figure 9-3 displays the setup for your Layer Teleport Curved Pointer game object so far.
Figure 9-3

The Layer Teleport Curved Pointer game object setup so far

You can test your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. Note that you won’t be able to teleport about within your VR world yet. However, you’ll be able to display your Layer Teleport Curved Pointer, which originates from your Headset, upon pressing your controller Left Thumbstick or the T key(spatial simulator mode).

Let’s now set up a valid Teleport area using layers. Your goal is to allow the player to teleport only to anywhere on the Floor, and not to any other game objects in the scene. Select the Floor game object in the hierarchy, and note that its layer has been set to Water. You need to allow the player to teleport onto any game object whose layer has been set to Water. Thus, if you were to assign the Table game object the layer of Water, the player should teleport onto the table.

In the hierarchy, select the Layer Teleport Curved Pointer game object and look at the Inspector. In the Pointer Facade component, there is a Target Validity property that will only accept a Rule game object in its Restriction Settings section. This property determines what the Layer Teleport Curved Pointer considers a valid Teleport target. As this property will accept a Rule object only, you need to set up a Rule for what the Layer Teleport Curved Pointer considers a valid target and then assign this Rule to the Target Validity property.

Select the Demo scene in the hierarchy. Create an empty game object as its child and reset its transform. Rename this game object “Rules.” All rules you create in this book will be stored as children of this Rules game object. Select the newly created game object in the hierarchy, and create an empty game object as its child and rename it “Teleport Layer.” With the Teleport Layer game object selected in the hierarchy, click the Add component button in the Inspector and add the Any Layer Rule component . Set its Layer Mask property to Water.

You have just created your first Teleport Layer rule. When attached to the Target Validity property of the Layer Teleport Curved Pointer game object, you can teleport anywhere in your Floor game object, as your Floor has been assigned the layer Water. Essentially, you have told your Layer Teleport Curved Pointer that any game object whose layer has been set to Water is considered a Valid (teleport) Target. The Layer Teleport Curved Pointer should display its default valid green color, allowing a teleport to occur. When the Layer Teleport Curved Pointer encounters a game object whose layer is not set to Water, the Layer Teleport Curved Pointer will be red, indicating an invalid teleport area.

Let’s set this up now. From within the hierarchy, drag and drop the Teleport Layer game object into the text box of the Target Validity property, as shown in Figure 9-4.
Figure 9-4

The Layer Teleport Curved Pointer game object setup so far

Playtest your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. You will notice that you still can’t teleport about within your VR World. However, when you press down on your controller’s Left Thumbstick or press the T key on the keyboard (in the Spatial Simulator mode) and direct the Layer Teleport Curved Pointer emitting from your headset to anywhere on the Floor, it will display in its valid green teleport state. However, if you direct the pointer at the table, ladder, or barrel, it will display its invalid red teleport state.

Setting up a Teleporter for Instant Teleportation

Instant Teleportation happens when a valid teleport area is found; at this point, the user is instantly repositioned, usually with a camera fade to eliminate motion sickness. In the last section, you set up your curved teleport pointer to facilitate teleportation. In this section, you’ll set up an Instant Teleporter game object that will enable you to teleport within your virtual world.

The Layer Teleport Curved Pointer is responsible for recognizing a valid teleport and initiating it. The Teleporter game object is responsible for moving the Play Area to a new location, which essentially moves your Virtual Player to this new location. You need to hook up the Teleporter to your Layer Teleport Curved Pointer so that the moment a valid Selection Action occurs and the Selected event on the Layer Teleport Curved Pointer is triggered, the Teleporter will execute its teleport functionality.

Let’s now set up this Teleporter game object. We can do this by selecting the VRTK SETUP game object in the hierarchy and creating a new empty child game object that we’ll rename “VRTK TELEPORTERS.” All Teleporters you create will be stored as children of this game object. Now, select the Project tab and expand the “Packages” folder. Locate the “Tilia Locomotors Teleporter Unity” folder and expand it until you reach its “Prefabs” folder. Select the folder, and from the pane on the right, drag and drop the Locomotors Teleporter Instant prefab onto the VRTK TELEPORTERS game object in the hierarchy.

From within the hierarchy, expand the Camera Rigs Tracked Alias game object. Then, expand its Aliases game object.

Select the Locomotors Teleporter Instant game object in the hierarchy, and ensure that its Teleporter Facade component has been expanded. You need to set up several properties here so that this Instant Teleporter knows what object should move when a teleport occurs and how it should be moved. In the Teleporter Settings section of the Teleporter Facade component, several properties need to be set.

The Target property indicates which game object should move when the Teleport method is called from the Layer Teleport Curved Pointer. The game object that needs to be moved here is the Play Area Alias. Doing this tells the Teleporter that when you teleport, Play Area Alias needs to be moved to the new location, which essentially moves your virtual player to its new location. Drag and drop the Play Area Alias game object from the hierarchy into the Target property text box, as shown in Figure 9-5.
Figure 9-5

Setting up the Instant Teleporter

For the Offset property , drag and drop the Headset Alias game object from the hierarchy into the Offset property text box, as shown in Figure 9-5. For the Offset Usage property, select Offset always with Destination Rotation, as shown in the figure. Now, upon being teleported to the destination, you will be rotated. This may be the effect you desire.

Check the box for the Apply Destination Rotation property, as shown in Figure 9-5. Then, drag and drop the Scene Cameras game object from the hierarchy into the Camera Validity property text box, as shown in the figure. This lets your Teleporter know about the cameras in the scene against which it can apply a camera blink. Last, set the Target Validity property to the Teleport Layer rule you created in the last section.

Last, you need to hook up this Locomotors Teleporter Instant game object to your Layer Teleport Curved Pointer. Do this by selecting the Layer Teleport Curved Pointer game object in the hierarchy. Expand its Selected event in the Inspector and click the plus symbol located in the bottom right-hand corner to add an event listener box. Now, drag and drop the Locomotors Teleporter Instant game object from the hierarchy into the event listener text box. For the function to execute when this event is invoked, select Teleporter Facade Teleport, available in the “Dynamic Event Data” section of the context menu that pops up, see Figure 9-6.
Figure 9-6

Hooking up the Instant Teleporter to the Layer Teleport Curved Pointer

Now, when the Left Thumbstick button or T key is pressed, your Layer Teleport Curved Pointer will be displayed, allowing you to select a point where you want to teleport to. At the same time, the Selection Action property emits a True value triggering the Selected event. This event executes its Teleporter Facade teleport method resulting in the player being teleported to the new location.

Playtest your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. You will see that you can now teleport about within your virtual world.

Setting Up a Teleporter for Dash Teleportation

Dash Teleportation can be thought of as a slight twist on Instant Teleportation. Dash Teleportation happens when a valid teleport area is found and the player gradually moves over time in a linear motion until the specific teleport point is reached. With Instant Teleportation, you probably noticed that you experience a fade effect. With Dash Teleportation, you’re jolted forward upon confirming your teleport destination.

Let’s get Dash Teleportation set up now. Within the hierarchy, select and expand the VRTK TELEPORTERS game object. Then, select the Project tab and expand the “Packages” folder. Locate the “Tilia Locomotors Teleporter Unity” folder and expand it until you reach its “Prefabs” folder. Select this folder, and from the pane on the right, drag and drop the Locomotors Teleporter Dash prefab onto the VRTK TELEPORTERS game object in the hierarchy.

From within the hierarchy, expand the Camera Rigs, Tracked Alias game object as well as its Aliases game object. Select the Locomotors Teleporter Dash game object in the hierarchy, and ensure that its Teleporter Facade component has been expanded. You now need to set up the same properties you did while setting up the Locomotors Teleporter Instant game object.

Drag and drop the Play Area Alias game object from the hierarchy into the Target property parameter, as shown in Figure 9-7. This tells the Teleporter that when you teleport, the Play Area Alias needs to be moved to the new location, which essentially moves your virtual player to its new location. For the Offset property, drag and drop the Headset Alias game object from the hierarchy into the Offset property parameter, as shown in the figure.
Figure 9-7

Setting up the Dash Teleporter

For the Offset Usage property , you’ll use a different value from the one you used for the Locomotors Teleporter Instant game object. We do this so that you can see how the rotation changes when you use a different setting. From the drop-down for this property, select Offset Always Ignore Destination Rotation, as shown in Figure 9-7. Now, upon being teleported to the destination, you won’t be rotated. This may be the effect you desire. Uncheck the box for the Apply Destination Rotation property, as shown in the figure. For the Camera Validity property, drag and drop the Scene Cameras game object from the hierarchy into the Camera Validity property parameter, as shown in the figure. Last, drag and drop the Teleport Layer game object from within the Rules game object to the Target Validity property parameter, as shown in Figure 9-7.

Finally, you need to hook up this Locomotors Teleporter Dash game object to your Layer Teleport Curved Pointer. In the hierarchy, select the Layer Teleport Curved Pointer game object. Expand its Selected event within the Inspector and click the plus symbol located in its bottom right-hand corner to add an event listener box. Now, drag and drop the Locomotors Teleporter Dash game object from the hierarchy into the event listener text box. For the function to execute when this event is invoked, select Teleporter Facade Teleport, available in the “Dynamic Event Data” section of the context menu that pops up. This setup is like what you see in Figure 9-6 except for the fact that the event listener text box has now been populated with the Locomotors Teleporter Dash game object.

Now, playtest your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. You’ll see that you can Dash teleport about within your virtual world and you won’t automatically be rotated upon reaching your destination. You might have noticed the subtle difference between an Instant and Dash teleport.

Well, now you can Instant and Dash teleport yourself about within your virtual world. However, it would be good if you could also rotate yourself around by pushing your Thumbstick to the left or right. In the next section, we’ll see how to set this up.

Rotating Around Within the Virtual World

Currently, if you want to rotate around within your virtual world, you need to use the mouse. In this section, we’ll set up rotation using your Left Controller’s Thumbstick so that you can both teleport and rotate using a single device. It’s not essential that you only set up rotation against your Left Controller’s Thumbstick; you can also set it up against your Right Thumbstick.

Let’s begin by setting up two intermediary game objects that we’ll use to capture Horizontal and Vertical Axis movement against your Left Controller’s Thumbstick. One intermediary game object will be responsible for capturing any Horizontal input movement emitted by all of the controllers’ Left Thumbsticks. The other intermediary game object will capture any Vertical input movement emitted by all of the controllers’ Left Thumbsticks. You’ll be capturing input against three devices, the Oculus, HTC Vive, and Xbox controllers. Your mouse has already been set up to allow you to rotate.

Select and expand the Button Input Actions game object in the hierarchy, and create two new empty child game objects within it. Rename the first child game object “Thumbstick Horizontal Axis Left.” When you move your controller’s Left Thumbstick horizontally, its input values will be captured here. Rename the second child game object “Thumbstick Vertical Axis Left.” When you move your controller’s Left Thumbstick vertically, this is where its input values will be captured. Select both of these game objects in the hierarchy and within the Inspector, click the Add Component button and add a Float Action component to both game objects. It’s important to note that your Thumbsticks’ horizontal and vertical movement yields a floating-point value that you need to capture. Therefore, you have to set up Float Action components on both intermediary game objects.

With the Thumbstick, Horizontal Axis Left and Thumbstick Vertical Axis Left game objects still selected in the hierarchy, expand the Sources property and change its size value to 3. Three Element slots will be made available to you. You’ll be capturing axis input against your Left Controllers’ Thumbsticks only against three devices—namely, the Oculus, HTC Vive, and Xbox Left Controllers.

Within the hierarchy, expand the VRTK INPUT CONTROLLERS game object.

Now, expand the Input Unity Input Manager Oculus Touch Left Controller until you locate the Left Thumbstick Horizontal Axis [1] game object. Then, expand the Input Unity Input Manager Open VR Left Controller until you locate the Left Trackpad Horizontal Axis [1] game object. Last, expand the Input Unity Input Manager, X-Box Controller until you locate the Left Thumbstick Horizontal Axis [Horizontal] game object.

Within the hierarchy, select the Thumbstick Horizontal Axis Left intermediary game object. You will consolidate the Left Thumbstick Horizontal Axis movement input from the Oculus, HTC Vive, and Xbox Left Controllers into this intermediary game object.

Drag and drop the Left Thumbstick Horizontal Axis [1] game object from the hierarchy into the Element 0 slot of the Float action component. Then, drag and drop the Left Trackpad Horizontal Axis [1] game object from the hierarchy into the Element 1 slot. Finally, drag and drop the Left Thumbstick Horizontal Axis [Horizontal] game object from the hierarchy into the Element 2 slot. You have now captured Horizontal Axis movement input against the Left Controller of three devices, as shown in Figure 9-8.
Figure 9-8

Setting up the Thumbstick Horizontal Axis Left intermediary game object

Within the hierarchy, select the Thumbstick Vertical Axis Left intermediary game object. You’ll consolidate the Left Thumbstick Vertical Axis movement input from the Oculus, HTC Vive, and Xbox Left Controllers into this intermediary game object.

Drag and drop the Left Thumbstick Vertical Axis [2] game object from the hierarchy into the Element 0 slot of the Float action component. Next, drag and drop the Left Trackpad Vertical Axis [2] game object from the hierarchy into the Element 1 slot of the Float action component. Finally, drag and drop the Left Thumbstick Vertical Axis [Vertical] game object from the hierarchy into the Element 2 slot of the Float Action component.

You have now captured Vertical Axis movement input against the Left Controller of three devices, as shown in Figure 9-9. This gives you a way to listen for Horizontal and Vertical Axis input against the Left Controller Thumbstick for all three devices.
Figure 9-9

Setting up the Thumbstick Vertical Axis Left intermediary game object

Playing Animation When the Left Thumbstick Is Flicked

When using the Camera Rigs, Spatial Simulator and X-Box Controller or Camera Rigs, Unity XR along with your custom prototype hands, you would ideally want to get some visual feedback against your custom virtual hands whenever you flick the Left Thumbstick on your controller horizontally or vertically. This visual feedback can be provided by playing the same Teleporting animation you play when you press down on the Left Thumbstick to teleport within the virtual world. You’ll play this Teleporting animation whenever you receive input after either a Horizontal or Vertical Left Thumbstick Axis flick has happened.

Let’s set up this animation for when a Horizontal or Vertical Axis Thumbstick movement occurs against your Left Controllers. Expand the Camera Rigs Tracked Alias game object in the hierarchy and then expand its Aliases game object. After that, expand the Left Controller Alias game object until you reach its Hand Proto Left game object.

Now, select the Thumbstick Vertical Axis Left intermediary game object in the hierarchy. Expand the Activated event In the Inspector and click the plus symbol located in its bottom right corner to add an event listener box to this Activated event. From the hierarchy, drag and drop the Hand Proto Left game object into the event listener box of the Activated event. For the function, select Animator Play (string) and in the text box below it, type in the name of the animation that should play (e.g., “Teleporting”), as shown in Figure 9-10.
Figure 9-10

Setting up the Teleporting animation to play when the Left Controller’s Thumbstick is flicked vertically

You have now set up the Teleporting animation to play whenever your Left Thumbstick is flicked vertically.

Now, from within the hierarchy, select the Thumbstick Horizontal Axis Left intermediary game object. Expand the Activated event in the Inspector and click the plus symbol located in the bottom right corner to add an event listener box to this Activated event. From the hierarchy, drag and drop the Hand Proto Left game object into the event listener box of the Activated event. For the function, select Animator Play (string), and in the text box below it, type in the name of the animation that should play (e.g., “Teleporting”), as shown in Figure 9-11.
Figure 9-11

Setting up the Teleporting animation to play when the Left Controller’s Thumbstick is flicked horizontally

You have now set up the Teleporting animation to play whenever your Left Thumbstick is flicked horizontally.

Rotating Using an Arrow Pointer

To enable yourself to rotate in the virtual world, you’ll need to set up an arrow pointer that you can rotate around using your Left Controller’s Thumbstick. This arrow pointer will be positioned at the very end of your curved teleport pointer. By rotating this arrow pointer around using the Thumbstick, you can have it face the direction you’d like to end up facing after being teleported.

Along with this book, you were provided an “Arrow_Pointer” unity package file that you need to import into your project now. Once imported, you’ll have the “Arrow Pointer” folder in your “Assets” folder. This folder contains an arrow pointer prefab that you will rotate around.

In the hierarchy, select the VRTK SETUP game object and create a new empty child game object within it. Rename this child game object “VRTK TELEPORT ROTATE.” You’ll set up the rotation mechanism here. It can only be used in conjunction with teleportation.

Select the Project tab and expand the “Packages” folder. Locate the “Tilia Input, Combined Actions, Unity” folder and expand it until you reach its “Prefabs” folder. Select the this folder, and from the pane on the right, drag and drop the Input Combined Actions Axes to Angle prefab onto the VRTK TELEPORT ROTATE game object in the hierarchy.

The Combined Actions prefabs allow you to create more complex input types like movement and rotation data. Here, you’ll use the Input Combined Actions Axes to Angle to convert the floating-point Thumbstick Axis data into rotation information, allowing you to rotate the arrow pointer.

Ensure that the VRTK TELEPORT ROTATE game object is selected in the hierarchy and create a new empty child game object within it. Rename this child game object “Pointer Rotator.” With this game object selected in the hierarchy, click the Add Component button in the Inspector and add a Float to Vector 3 component. This component will emit a rotation angle as a Euler angle that rotates the arrow pointer.

With the Pointer Rotator game object still selected in the hierarchy, click the Add Component button in the Inspector and add the Transform Euler Rotation Mutator component to this game object. The Float to Vector 3 component will emit a Euler rotation angle to the Transform Euler Rotation Mutator component , rotating the arrow pointer.

Now, select the Layer Teleport Curved Pointer in the hierarchy. It is a child of the VRTK RAY POINTERS game object. Expand the pointer until your reach its Valid Container child game object and select it. This game object can be found by navigating to Layer Teleport Curved Pointer ➤ Object Pointer Internal ➤ Elements ➤ Destination ➤ Elements Cylinder ➤ Valid Container.

The Arrow prefab is located within your Assets ➤ Arrow Pointer ➤ Prefabs folder . Drag and drop this Arrow prefab onto the Valid Container game object in the hierarchy, making the game object a child.

Now, select the Arrow game object in the hierarchy and adjust its Transform properties as follows: Set the Transform, Position to: X = 0; Y = 0.2; and Z = -0.136. Set its Transform, Rotation Z value to 90.

Then, select the Pointer Rotator game object in the hierarchy. It is available as a child of the VRTK TELEPORT ROTATE game object you created in this section. Next, drag and drop the Valid Container game object into the Target property parameter of the Transform Euler Rotation Mutator component, as shown in Figure 9-12.
Figure 9-12

Setting up the Transform Euler Rotation component on the Pointer Rotator game object

Within the Mutate on Axis property of the Transform Euler Rotation Mutator component, uncheck the X and Z boxes, as shown in Figure 9-12. You want only the box for the Y-axis to be checked, as your arrow pointer just needs to rotate around this axis to face a new direction in the scene.

With the Pointer Rotator game object still selected in the hierarchy, expand its Float to Vector 3 component as well as its Transformed (Vector 3) property. Click the plus button in the bottom right corner of the property to add an event listener box, as shown in Figure 9-13.
Figure 9-13

Setting up the Float to Vector 3 component on the Pointer Rotator game object

Now, drag and drop the Transform Euler Rotation Mutator component of the Pointer Rotator game object into the event listener text box of the Transformed (Vector 3) property. For the function to perform, first select Transform Euler Rotation Mutator from the drop-down and then the Do Set Property item in the Dynamic Vector 3 section, as shown in Figure 9-13.

Now, select the Input Combined Actions Axes to Angle game object in the hierarchy. It is available as a child of the VRTK TELEPORT ROTATE game object you created in this section. Next, expand the Button Input Actions game object in the hierarchy. Drag and drop the Thumbstick Horizontal Axis Left game object into the Horizontal Axis property parameter of the Axes to Angle Action component. Then, drag and drop the Thumbstick Vertical Axis Left game object into the Vertical Axis property parameter of the Axis to Angle Action component. Next, drag and drop the Headset Alias game object into the Direction Offset property parameter of the Axes to Angle Action component. Figure 9-14 shows the Input Combined Actions Axes to Angle game object setup so far.
Figure 9-14

Setting up the Input Combined Actions Axes to Angle game object

Expand the Value Changed event and click the plus button located in its bottom right corner to add an event listener text box. Drag and drop the Pointer Rotator game object into the text box of the Value Changed event . For the function to execute when the Value Changed event is triggered, select Float to Vector 3 from the drop-down and then select Current Y, available within the Dynamic Float section of the context menu that pops up, see Figure 9-15.
Figure 9-15

Setting up the Value Changed event and Deadzone settings for the Input Combined Actions Axes to Angle game object

Now, add another event listener text box to the Value Changed event . Drag and drop the Pointer Rotator game object into this text box. For the function to execute when the Value Changed event is triggered, select Float to Vector 3 from the drop-down and then select the Do Transform item in the Static Parameters section of the context menu that pops up, see Figure 9-15.

Next, set the Horizontal and Vertical Deadzone bounds to -0.55 and 0.55, as shown in Figure 9-15. These Deadzone values indicate that you need to push your Thumbsticks over these set threshold values to trigger a button input action. You may want to further tweak these values to your liking.

Finally, note that you’re still in Dash Teleport mode. To enable yourself to teleport and face your arrow pointer’s direction, you need to change two settings on your Locomotors Teleporter Dash game object, which you’ll find nested within the VRTK TELEPORTERS game object in the hierarchy. Select the Locomotors Teleporter Dash game object in the hierarchy. In the Inspector, set the value of the Offset Usage property to Offset Always with Destination Rotation. Also, check the box for the Apply Destination Rotation property . This will enable you to face the direction your arrow pointer was pointing upon being teleported.

Note that when teleporting, you must rotate your arrow pointer to face a new direction while keeping your Left Thumbstick pressed down. This may require some finger dexterity on your part. Once you have your arrow pointer pointing in the direction you want to end up facing, release your hold against your Left Thumbstick.

You’ll be teleported to the new location facing the direction your arrow pointer was rotated.

You can playtest your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. Note that you can rotate the arrow pointer at the end of your Curved Teleport Ray by pressing down on your Left Thumbstick button and moving your Left Thumbstick either forward, backward, left, or right. This allows you to change the direction of your arrow pointer in 90-degree increments. With your Left Thumbstick button still pressed down, roll the Left Thumbstick so that the arrow pointer moves around in smaller increments. You’ll be teleported to the new location upon releasing your hold on the Left Thumbstick. You’ll notice that you’ve been rotated to face the direction your arrow pointer was facing. You can now rotate and teleport onto any location of the Floor using your controllers.

Unity’s NavMesh-Based Teleportation

In this section, we’ll use Unity’s NavMesh to map out a valid teleport area within your scene. This will allow you to teleport anywhere within this valid NavMesh area. Setting up NavMesh is hugely beneficial, as you can create AI enemy bots that can navigate it.

To set up NavMesh, you need some static geometry in your scene that can be baked into Unity NavMesh. Ensure that the Gizmos button on your Scene tab has been toggled on, as shown in Figure 9-16.
Figure 9-16

Setting up the baked NavMesh in Unity

You’ll use the Containers, Barrels, Table, Ladder, and Floor game objects available in the Demo scene for static geometry. In the hierarchy, expand the Environment game object and select the Floor game object. Check the Static box, located in the upper right-hand corner of the Inspector. Next, expand the Containers game object in the hierarchy, and select all the container game objects in it. In the Inspector, check the Static box. Next, expand the Barrels game object in the hierarchy, and select all the barrel game objects within it. In the Inspector, check the Static box to ensure every barrel is marked static. Now, select the Table game object in the hierarchy. Check its Static box, located in the upper right-hand corner of the Inspector. When prompted to enable the static flags for all the child objects, select the button Yes, Change Children. Finally, select the Ladder game object in the hierarchy. Check its Static box, located in the upper right-hand corner of the Inspector. When prompted to enable the static flags for all the child objects, select the button Yes, Change Children.

Now, you need to bake a Unity NavMesh into your scene. From the main menu within the Unity Editor, select Window ➤ AI ➤ Navigation. This opens a new Navigation tab beside the Inspector tab. Select the Navigation tab, and click on the Bake tab located at the top. Set the Agent Radius property to 0.5. Ensure the Agent height property is set to 2, the Max Slope property is set to 45, and the Step Height property is set to 0.4. The other property values on the Bake tab can stay at their defaults. Now, click the Bake button to have Unity bake a NavMesh. You should see a fleeting progress bar baking the NavMesh for your scene in the bottom right-hand corner of the Unity Editor window. Upon completion, you’ll see the baked NavMesh in your scene, as shown in Figure 9-16.

If you don’t see the baked NavMesh as displayed above, ensure that your Gizmos button has been toggled on and the Show NavMesh button box has been checked. Once you have baked your Unity NavMesh, you need to set up a rule telling your Layer Teleport Curved Pointer to only consider your Unity NavMesh area as a valid Teleport Target.

Expand the VRTK RAY POINTERS game object in the hierarchy and select the Layer Teleport Curved Pointer game object. This curved pointer allows you to teleport anywhere within your Floor or onto any object whose layer has been set to Water. Currently, only the layer of your Floor game object has been set as such. Now, let’s create a new NavMesh rule that will tell your Layer Teleport Curved Pointer that it can teleport the player only within the limits of the NavMesh setup.

Select and expand the Rules game object in the hierarchy, and create a new empty game object and rename it “Teleport NavMesh.” Select this game object in the hierarchy and within the Inspector, click the Add Component button to add a new NavMesh Rule component.

Now, select the Layer Teleport Curved Pointer game object in the hierarchy, and within the Inspector, locate its Target Point Validity property within the Restriction Settings section. Drag and drop the Teleport NavMesh rule game object you just created into this Target Point Validity property parameter.

Note that you now have two rules in place, one that you just set up against the Target Point Validity property and another that already existed for the Target Validity property. Remove the Target Validity property rule by right-clicking the Target Validity property label and selecting Revert from the context menu that pops up. This ensures that your Layer Teleport Curved Pointer has just the one rule it needs to comply with now, which is the Teleport NavMesh rule.

In the Pointer Facade component of your Layer Teleport Curved Pointer game object, scroll down to the bottom, locate its Selected event, and expand it. Click the object within its event listener box to have the Locomotors Teleporters Dash game object highlight within the hierarchy. Select this game object and locate its Target Validity property in the Inspector. Note that this property has been set to the Teleport Layer rule. Remove this rule by right-clicking the Target Validity property label and selecting Revert from the context menu that pops up. Next, select the Locomotors Teleporter Instant game object in the hierarchy and locate its Target Validity property within the Inspector. Remove this Teleport Layer rule as well. Now you can be assured that your Layer Teleport Curved Pointer will only use the Teleport NavMesh rule to teleport the player.

Playtest your scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. Note that you can teleport about as before. As long as you aim your Layer Teleport Curved Pointer within the bounds of the NavMesh area, your teleport pointer will display in its valid green state and you’ll be able to teleport. The moment your Layer Teleport Curved Pointer aims at a spot outside the bounds of the NavMesh, like somewhere very close to a Container or Barrel edge, its invalid red state will be activated.

Teleporting Using Teleport Targets

In this chapter’s final section, you’ll set up Teleport Targets, which are ideally used when the player needs to cover large distances, like when traversing massive terrains. Some VR experiences won’t allow you to teleport everywhere. Instead, they rely on fixed hotspots, or Teleport Targets, to limit the player’s movement about the virtual world to using these Teleport Targets. These targets are the VRTK’s prefabs for earmarking certain specific points or areas that you can teleport to. They are ideal for creating immersive experiences and puzzle games like Mist and Riven. Also, if your VR experience requires you to traverse large terrains, strategically positioned Teleport Targets will help create a great VR experience.

The VRTK allows you to achieve this targeted teleportation by providing two prefabs, a Teleport Targets Point and a Teleport Targets Area . In this section, you’ll learn to set up both types of Teleport Targets.

Start by selecting the Demo scene game object within the hierarchy and creating a new empty game object in it. Rename it “Teleport Targets.” All your Teleport Targets, be they Point or Area Teleport Targets, will reside as children within this Teleport Targets game object.

Let’s now set up a couple of Teleport Target points. Expand the “Packages” folder within the Project tab; locate the Tilia Locomotors, Teleport Targets Unity package; and expand it until you reach its “Prefabs” folder. In this folder, drag and drop the Locomotors Teleport Targets Point prefab onto the Teleport Targets game object in the hierarchy. Rename the game object “Locomotors Teleport Targets Point Zero,” and set its Transform Position values as follows: X = -18; Y = 0; and Z = -2. Then, duplicate this game object twice, so that you have, in total, three Teleport Target Points in the scene. Rename these new points “Locomotors Teleport Targets Point One” and “Locomotors Teleport Targets Point Two.” Select the former point in the hierarchy and set its Transform Position values to X = -9; Y = 0; and Z = -2. Then, select the latter and set the following values: X = -13.5; Y = 0; and Z = -8.

For Teleport Targets to work, you need a Spatial Target Dispatcher in your scene. I made this prefab available to you in the VRTK. Let’s set this up first, and then I will explain how it works. In the hierarchy, select the VRTK SETUP game object and create a new empty child game object within it. Rename the child game object “VRTK SPATIAL TARGET DISPATCHER.”

Expand the “Packages” folder within the Project tab and locate the Tilia Indicators, Spatial Targets, Unity package. Expand it until you reach its “Prefabs” folder. In this folder, drag and drop the Indicators Spatial Targets Dispatcher prefab onto the VRTK SPATIAL TARGET DISPATCHER game object in the hierarchy.

Now, expand the VRTK RAY POINTERS game object in the hierarchy. Duplicate its Layer Teleport Curved Pointer child game object, and rename the copied game object “Spatial Target Teleport Curved Pointer.” This descriptive name emphasizes that this pointer is exclusively dedicated to teleporting to spatial target points and areas. You need this new dedicated Spatial Target Teleport Curved Pointer, as its setup is different from that of the Layer Teleport Curved Pointer, which can only be used with the standard and NavMesh-based teleportation you set up in earlier sections, not when you want to teleport about using spatial target points or areas.

With the Spatial Target Teleport, Curved Pointer selected in the hierarchy, locate its Selected event within the Pointer Face component of the Inspector and delete the Locomotors Teleporter Dash item from within the event listener text box. You won’t be calling the Dash Teleporter directly when a Selection Action occurs. Instead, you need to call the Indicators Spatial Targets Dispatcher.

Ensure that the Spatial Target Teleport Curved Pointer game object is selected within the hierarchy, and then locate and expand the VRTK SPATIAL TARGET DISPATCHER game object in the hierarchy. Drag and drop the Indicators Spatial Targets Dispatcher into the Selected event text box within the Pointer Facade component of the Spatial Target Teleport Curved Pointer game object. For the function, select Spatial Target Dispatcher, Do Dispatch Select from within the Dynamic Event Data section, as shown in Figure 9-17.
Figure 9-17

Setting up the Spatial Target Teleport Curved Pointer to call on the Indicators Spatial Targets Dispatcher when the Selected, Entered, and Exited events are triggered

Next, you need to set up the Entered event on the Pointer Facade component of the Spatial Target Teleport Curved Pointer game object. Expand the Entered event and click the plus symbol located in the bottom right corner to add a new event listener. Drag and drop the Indicators Spatial Targets Dispatcher into the Entered event text box within the Pointer Facade component of the game object. For the function, select Spatial Target Dispatcher, Do Dispatch Enter from within the Dynamic Event Data section, as shown in Figure 9-17.

Last, you need to set up the Exited event on the Pointer Facade component of the Spatial Target Teleport Curved Pointer game object. Expand the Exited event and click the plus symbol located in the bottom right corner to add a new event listener. Drag and drop the Indicators Spatial Targets Dispatcher into the Exited event text box within the Pointer Facade component of the Spatial Target Teleport Curved Pointer game object. For the function, select Spatial Target Dispatcher, Do Dispatch Exit from within the Dynamic Event Data section, as shown in Figure 9-17.

Note that as the three Teleport Target Points in the Demo scene are Spatial Targets, they can receive the three events you have set up above: Do Dispatch Select, Do Dispatch Enter, and Do Dispatch Exit. These events get called when any of the three Teleport Target Points are selected, entered, or exited.

The three Teleport Targets you’ve set up are spatial targets that need to receive a Dispatch event from a Spatial Targets, Dispatcher. Your Spatial Target Teleport Curved Pointer will now no longer directly call on the Instant or Dash Teleporter within its Selected event; instead, it will call on the Indicators Spatial Targets Dispatcher set up for its Selected, Entered, and Exited events .

Each Teleport Target Point is a spatial target that can receive any Dispatch event emitted by the Spatial Targets Dispatcher. Whenever the Selection Action is activated on the Spatial Target Teleport Curved Pointer, its Selected event is triggered, which in turn calls on the Do Dispatch Select method of the Indicators Spatial Targets Dispatcher.

As your Teleport Target Points are spatial targets, they can receive a Dispatch event emitted by the Indicators Spatial Targets Dispatcher directed at the selected Teleport Target Point. When they receive this Dispatch event, their Activated event gets triggered, wherein the Teleport method then calls on either the Instant or Dash Teleporter. We’ll set up this Activated event on all three Teleport Target Points in the Demo scene shortly.

Before proceeding further, let’s select the Layer Teleport Curved Pointer game object in the hierarchy and deactivate it, as two Teleport Pointers can’t be active at the same time. As we’ll be working with Spatial Teleport Point and Area Targets that require the Spatial Target Teleport Curved Pointer game object, we need to ensure that only this game object is active in the hierarchy.

Select the Spatial Target Teleport Curved Pointer game object in the hierarchy. Then, choose the Target Point Validity property label in the Pointer Facade component of the Inspector, right-click it, and select Revert to remove the Rule set up against this property.

You’ll need to set up a new rule for the Target Validity property . The very first Teleport Layer rule you created that was assigned to this property enabled you to teleport onto any object that had its layer set to Water, which was your Floor game object.

When using Teleport Target Points, or areas, your goal is to not allow the player the freedom to teleport anywhere within the level except these predefined points. To achieve this, you need to negate the Teleport Layer rule and assign it to the Target Validity property. The Teleport Layer rule encompasses the entire Floor object. When you negate this rule, it results in the player being unable to teleport anywhere on the Floor object, which will work well because the player will then be forced to teleport only onto the Teleport Target Points, or areas that have been set up.

Let’s begin by setting up a new rule that negates your Teleport Layer rule. Then, we’ll use this negated rule as the value for the Target Validity property of the Spatial Target Teleport Curved Pointer game object.

From within the hierarchy, select and expand the Rules game object and create a new child game object in it. Rename the child game object “! Teleport Layer” to represent a Negated Teleport Layer rule. With the ! Teleport Layer game object selected in the Inspector, add a new Negation Rule component to it. Drag and drop your Teleport Layer rule from the hierarchy into the Rule text box of this Negation Rule component . Thus, you can quickly negate an existing rule by simply using the Negation Rule component, as shown in Figure 9-18.
Figure 9-18

Setting up the Negated Teleport Layer rule

Now, select the Spatial Target Teleport Curved Pointer game object in the hierarchy. Then, drag and drop the ! Teleport Layer rule game object from the hierarchy into the Target Validity property parameter in the Pointer Facade component of the Spatial Target Teleport Curved Pointer game object, as shown in Figure 9-19.
Figure 9-19

Hooking up the Negated Teleport Layer rule to the Target Validity property of the Spatial Target Teleport Curved Pointer game object

As you’ll want to retain the ability to rotate the arrow pointer when teleporting using the Teleport Target Points, or areas, you’ll need to change the Target property of your Pointer Rotator game object. Currently, this property points to the Valid Container game object in the Layer Teleport Curved Pointer game object that you deactivated. You need to have the property point to the Valid Container in the Spatial Target Teleport Curved Pointer game object. This is the pointer you’ll be using with the Teleport Target Points, or areas.

Let’s set this up now. In the hierarchy, select and expand the VRTK TELEPORT ROTATE game object and then select its child Pointer Rotator game object. In the Inspector in the Transform Euler Rotation Mutator component, select the Target property and delete the Valid Container game object. Now, expand the Spatial Target Teleport Curved Pointer game object until you locate the Valid Container game object that contains your arrow pointer. This game object can be found by navigating as follows: Spatial Target Teleport Curved Pointer ➤ Object Pointer Internal ➤ Elements ➤ Destination ➤ Elements Cylinder ➤ Valid Container.

Drag and drop the Valid Container game object from the hierarchy into the Target property of the Transform Euler Rotation Mutator component of the Pointer Rotator game object, as shown in Figure 9-20. You have now completed the setup of your Spatial Target Teleport Curved Pointer.
Figure 9-20

Setting up the Valid Container game object on the Pointer Rotator

Let’s now configure the Activated events for the three Teleport Target Points in your Demo scene. Select and expand the Teleport Targets game object in the hierarchy, and then select all three Teleport Target Points in that object. Within the Inspector, ensure that the Spatial Target Facade component has been expanded. Within the Target Events section, locate and expand the Activated event. Click the plus symbol located in the bottom right corner of this Activated event to add an event listener box, see Figure 9-21.
Figure 9-21

Setting up Teleport Targets Points to use a Dash teleport for teleportation from one Target Point to another

Now, from within the VRTK TELEPORTERS game object, drag and drop either the Instant or Dash Teleporter game object into the event listener box of the Activated event within the Spatial Target Facade component of the Teleport Target Point game objects. For the function, select Teleporter Facade, and from the context menu that pops up, select the Teleport item in the “Dynamic Data Surface” section, as shown in Figure 9-21.

Playtest your Demo scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups. First, try teleporting anywhere in the confines of the Floor. Note that you won’t be able to do so. Now, point toward any of the Teleport Target Points until you see your green teleport ray dipping into it. Upon releasing your Left Thumbstick, you’ll be teleported to that point. Play around by teleporting to either of the other two visible Teleport Target Points available. Note that once you teleport yourself onto a Teleport Target Point, it is turned off. Rotate your arrow pointer to ensure that you are oriented in the direction your arrow pointer was rotated upon being teleported to your Target Point.

Now, let’s set up a Teleport Target Area, which works similarly to a Teleport Target Point. The benefit of a target Area is that it allows you to define a much larger area or zone that you can teleport to.

From within the hierarchy, select and expand the TELEPORT TARGETS game object. With the Project tab, select and expand the “Packages” folder. Locate the Tilia Locomotors Teleport Targets Unity package. Expand it until you reach its “Prefabs” folder. From within this folder, drag and drop the Locomotors Teleport Targets Area prefab onto the TELEPORT TARGETS game object in the hierarchy. Set its Transform Position values to X = -12.82; Y = 0; and Z = -4.24. Set its Transform Scale values to X = 3; Y = 1; and Z = 3. This provides you with a square Teleport Target Area. Note that you can change the size of your target area by simply changing the X and Z values of its Transform Scale property.

Select the Locomotors Teleport Targets Area game object in the hierarchy, and within the Inspector, ensure that its Spatial Target Facade component has been expanded. Within the “Target, Events” section, locate and expand the Activated event. Click the plus symbol located in the bottom right corner of this Activated event to add an event listener box.

Now, from within the VRTK TELEPORTERS game object, drag and drop either the Instant or Dash Teleporter game object into the event listener box of the Activated event, within the Spatial Target Facade component of the Locomotors Teleport Targets Area game object. For the function, select Teleporter Facade, and from the context menu that pops up, select the Teleport item available in the Dynamic Data Surface section, as shown in Figure 9-22.
Figure 9-22

Setting up Teleport Targets Area to use an Instant teleport for teleportation

Playtest your Demo scene using the Camera Rigs, Spatial Simulator and the Camera Rigs, Unity XR setups by teleporting yourself into the Teleport Targets area you’ve set up. Then, teleport to the other Teleport Target Points. You’ll find that you can only teleport between your newly set-up Teleport Targets area and the three Teleport Target points. You can’t teleport anywhere else within the Demo scene.

Summary

This chapter has taught you all you need to know about teleportation using the VRTK. We started by reviewing what teleportation is and why it is considered one of the better forms of locomotion in the VR world. We went on to capture input for pressing the Left Thumbstick against your controllers and the T key against the keyboard.

We consolidated all these inputs into an intermediary game object. We then set up a curved teleport pointer and learned how to hook it up to this intermediary game object. We created our first Teleport Layer rule that allowed us to teleport onto any object whose layer had been set to Water.

You learned about the two types of teleporter prefabs provided by the VRTK and went on to set up Instant and Dash teleportation mechanics. You also learned the subtle differences between these teleport methods. We went on to set up rotation to enable ourselves to rotate around in the virtual world using our controllers.

We set up an arrow pointer to provide a visual cue of the direction we’d like the player rotated upon being teleported. You learned how to use the Transform Euler Rotation Mutator component to rotate the arrow pointer and player within the virtual world.

We then turned our attention to using Unity’s NavMesh and created a new Teleport NavMesh rule to enable teleportation to a Unity NavMesh. You learned about Teleport Targets as the other method available for teleporting around in the virtual world. You learned that you could either create Teleport Target Points or a Teleport Target area.

We first created three Teleport Target Points, or areas, in our Demo scene and saw that these target points require a particular VRTK prefab, the Indicators Spatial Target Dispatcher, to function. We set up an Indicators Spatial Target Dispatcher to dispatch events to Teleport Target Points and areas. We then created a negated Teleport Layer rule that assisted us with teleportation using Teleport Target Points or areas.

We created a new Spatial Target Teleport Curved Pointer to use when teleporting using spatial target points or areas. You learned that only one curved teleport pointer could be active in the scene at any time. We hooked up the Activated event on our Teleport Target Points, which was responsible for ensuring that teleportation occurred flawlessly. We ended the chapter by setting up a Teleport Target area and playtested our Demo scene to ensure that all our Teleport Targets were working.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.171.253