In this chapter, we’ll look at an immersive movement mechanism that allows players to move smoothly in the VR world. If your game or experience is immersive, it’s more convincing if the illusion of immersion isn’t constantly being broken in the teleport movements. Seamless locomotion is also commonly referred to as slide movement and rotation. It’s worth noting that this form of locomotion isn’t for everyone. Players who are new to VR or just sensitive to it may not find this sliding movement and rotation comfortable, and it can cause nausea. Using seamless locomotion, the player can move around the virtual world by simply gliding along the floor surface, moving forward, back, or strafing left and right. The VRTK provides you with four ways to achieve this seamless locomotion, with each form involving a very subtle change. We’ll learn to implement all four forms of seamless locomotion provided in the VRTK.
Capturing Horizontal and Vertical Axis Input
In the last chapter, you used a Float Action component to capture your Left Thumbstick’s vertical and horizontal movement input. You created the Thumbstick Horizontal and Vertical Axis Left game objects to capture this input from three devices: the Oculus, HTC Vive, and Xbox left controllers. These game objects are available as children of the Button Input Actions game object. We’ll now look at another method for capturing vertical and horizontal movement input against your Thumbsticks.
An alternative to using a Float Action component to capture a controller’s horizontal or vertical movement input is to use the VRTK-provided 1D Axis Action. Both methods will provide you with the same result; however, it’s good to understand all the options you have available.
Let’s begin implementing this new 1D Axis Action. From within the hierarchy, select and expand the Button Input Actions game object, and expand the “Packages” folder in the Project tab and locate the Tilia Input Unity Input Manager package . Expand it until you reach its “Actions” folder in the “Prefabs” folder. In the right pane of the “Actions” folder, you’ll see the Input Unity Input Manager 1D Axis Action prefab. Drag and drop this prefab onto the Button Input Actions game object in the hierarchy. Rename this Input Unity Input Manager 1D Axis Action game object “Thumbstick Horizontal Axis Input.”
Strafing Movement
Strafing is the simplest form of seamless locomotion provided by the VRTK. With this form of locomotion, you can move forward, backward, left, and right. Let’s set this up now.
Select the VRTK SETUP game object in the hierarchy and create a new empty child game object in it. This game object will contain all possible seamless locomotion mechanics provided by the VRTK. Rename this new empty child game object “VRTK PLAYER SLIDE ROTATE.”
Expand the “Packages” folder in the Project tab, locate the Tilia Locomotors Axis Move Unity package, and expand it until you reach its “Prefab” folder. In the right pane of this folder, you’ll see four prefabs provided by the VRTK that allow for seamless movement and rotation. Each of these prefabs offers a subtle variant of the slide movement and rotation.
Drag and drop the Locomotors Axis Move Vertical-Slide Horizontal-Slide prefab onto the VRTK PLAYER SLIDE ROTATE game object in the hierarchy. With the Locomotors Axis Move Vertical-Slide Horizontal-Slide game object selected in the hierarchy, rename it “Locomotors Axis Move Vertical-Slide Horizontal-Slide STRAFING.”
Now, we need to set up the properties in the “Target Settings” section. The Target property determines which object will slide around the scene. As you want to move within the scene, you’ll need to move your Play Area Alias around. Drag and drop the Play Area Alias game object from the hierarchy into this Target property parameter, see Figure 10-3.
The Forward Offset property is used to determine which game object should be used to determine your forward direction. As you always walk forward in the direction you’re facing, you need to set this property to your Headset Alias game object. Drag and drop this game object from the hierarchy into the Forward Offset property parameter, as shown in Figure 10-3.
Ideally, we’d have some animation play as we flick our Thumbstick forward, back, left, or right. We’ll use the same Teleporting animation we did when we implemented the Thumbstick Horizontal Axis Left and Thumbstick Vertical Axis Left game objects.
Now, from within the Avatar container for the Left Controller Alias, drag and drop the Hand Proto Left game object into the event listener box of the Activated event. For this function, select the Animator Play string. For the name of the animation to play, type “Teleporting” into the text box below, as shown in Figure 10-4.
Playtest your Demo scene using your VR headset with the Camera Rigs, Unity XR setup and your Xbox controller with the Camera Rigs, Spatial Simulator setup. Notice that you can now slide yourself forward and back by pushing your left controller Thumbstick up and down. You’ll also notice your left hand playing the Teleporting animation. Strafing has also been enabled, wherein pushing your Thumbstick toward the left causes you to move left and pushing it to the right causes you to move right. This is an elegant and simplistic behavior provided by the Locomotors Axis Move Vertical-Slide Horizontal-Slide prefab.
Free Movement Smooth Rotation
As the name suggests, the Free Movement Smooth Rotation prefab allows you not only to slide smoothly and freely but also to rotate smoothly and freely. However, in my opinion, this smooth rotation is inclined to induce motion sickness for all forms of seamless locomotion discussed in this chapter.
Your “Tilia Locomotors Axis Move Unity Package Prefabs” folder should still be expanded. From it, drag and drop all three remaining prefabs, the Locomotors Axis Move Vertical-Slide Horizontal-Smooth Rotate, Locomotors Axis Move Vertical-Slide Horizontal Snap Rotate, and Locomotors Axis Move Vertical Warp Horizontal Snap Rotate, onto the VRTK PLAYER SLIDE ROTATE game object in the hierarchy.
Deactivate all three newly added Locomotor game objects in the hierarchy, as just one can be active at any point in time. Select the Locomotors Axis Move Vertical-Slide Horizontal-Smooth Rotate game object in the hierarchy, and rename it “Locomotors Axis Move Vertical-Slide Horizontal-Smooth Rotate FREELY.”
The Camera Rigs, Tracked Alias game object and its Aliases game object should already be expanded in the hierarchy. Drag and drop the Play Area Alias game object from the hierarchy into the Target property parameter, see Figure 10-5.
Next, drag and drop the Headset Alias game object from the hierarchy into the Forward Offset property parameter, as shown in Figure 10-5.
To enable rotation, we need to set up the Rotation Pivot property . The Rotation Pivot is a designated pivot point around which your Target will rotate. You have set your Target property to the Play Area Alias, so your Play Area Alias needs to rotate around this designated pivot point. Also, this pivot point needs to be a child game object of your Play Area Alias. Expand the Play Area Alias game object in the hierarchy and you’ll see that nested within it is its child, the Headset Origin game object, which you can use as the Rotation Pivot.
Drag and drop the Headset Origin game object from the hierarchy into the Rotation Pivot property parameter, as shown in Figure 10-5. Then, drag and drop the Scene Cameras game object from the hierarchy into the Scene Cameras property parameter, as also shown in the figure.
Last, activate the Locomotors Axis Move Vertical-Slide Horizontal-Smooth Rotate FREELY game object in the hierarchy and deactivate the Locomotors Axis Move Vertical-Slide Horizontal-Slide STRAFING game object, as you can’t have more than one of these game objects active at one time.
Playtest your Demo scene using your VR headset with the Camera Rigs, Unity XR setup and your Xbox controller with the Camera Rigs, Spatial Simulator setup. Notice that you can now slide yourself about by pushing your left controller’s Thumbstick forward and backward. You can also rotate yourself around by pushing your left controller’s Thumbstick left or right. Play around with this free-flowing sliding movement and rotation you’ve set up. It’s also important to note that if you keep your Left Thumbstick continually pressed either to the left or to the right you’ll keep rotating, which can cause motion sickness.
Free Movement Snap Rotation
As the name suggests, the Free Movement Snap Rotation prefab provides you a smooth sliding movement with a snap rotation, allowing you to snap rotate to face a new direction in predefined degree increments. It also provides you with an optional fade-in or fade-out with each snapped rotation. This will dramatically reduce the motion sickness you may have encountered with the smooth rotation set up in the earlier section (Free Movement Smooth Rotation).
Let’s start setting it up by activating the Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate game object in the hierarchy and deactivating the Locomotors Axis Move Vertical-Slide Horizontal-Smooth Rotate FREELY game object. Note that you can’t have more than one of these Locomotors game objects active at one time.
The Camera Rigs , Tracked Alias game object and its Aliases game object should already be expanded in the hierarchy. Drag and drop the Play Area Alias game object from the hierarchy into the Target property parameter, as shown in Figure 10-6.
Next, drag and drop the Headset Alias game object from the hierarchy into the Forward Offset property parameter, as shown in Figure 10-6. With the Play Area Alias game object expanded in the hierarchy, drag and drop the Headset Origin game object into the Rotation Pivot property parameter, also shown in the figure.
Ideally, you want your camera view to fade in and fade out each time you snap rotate, as this would reduce any potential motion sickness caused by an instant snap rotation. The Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate prefab has already been set up to fade. However, you need to tell it which cameras to fade.
Drag and drop the Scene Cameras game object from the hierarchy into the Scene Cameras property parameter. This lets your Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate game object know that it needs to fade out these scene cameras each time a snap rotation occurs, see Figure 10-6.
You may want to change the amount of rotation that is applied per snap. By default, whenever a snap rotation occurs, you are rotated 45 degrees. A 45-degree snap rotation works well and there is no need to change it. However, just so you know where and how this change can be made, let’s change the snap rotation to 35 degrees. To do this, we’ll need to drill down into the Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate game object.
Select this game object in the hierarchy and expand it until you reach its Input Axis game object. You can do this by navigating as follows: Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate ➤ Internal ➤ Rotation Mutator ➤ Input Axis.
Let’s playtest the Demo scene using our VR headset with the Camera Rigs, Unity XR setup and our Xbox controller with the Camera Rigs, Spatial Simulator setup. Note that you can now slide yourself about by pushing your left controller’s Thumbstick forward and backward. You can also rotate yourself around by pushing your left controller’s Thumbstick left or right. Also note that you can’t keep your left controller Thumbstick continually pushed left or right, which was possible with the Free Movement Smooth Rotation, so expect to keep snap rotating. However, you’ll notice that you can now snap rotate in 35-degree increments and fade in and fade out with each rotation, which essentially eliminates motion sickness.
Free Movement Warp Snap Rotation
The difference between the Snap Rotation and the Warp Snap Rotation is that Warp Snap Rotation provides you with a vignette effect when moving forward, backward, and rotating. In the case of the Snap Rotation, you can keep your Left Thumbstick continually pressed either forward or backward and you will continue to move in the world, which isn’t possible with Warp Snap Rotation. With the latter, for every forward and backward movement, you need to push or pull against your Left Thumbstick.
Activate the Locomotors Axis Move Vertical Warp Horizontal Snap Rotate game object in the hierarchy and deactivate the Locomotors Axis Move Vertical-Slide Horizontal-Snap Rotate game object, as you can’t have more than one of these Locomotors game objects active at one time.
The Camera Rigs, Tracked Alias game object and its Aliases game object should already be expanded in the hierarchy. Drag and drop the Play Area Alias game object from the hierarchy into the Target property parameter, as also shown in Figure 10-8.
Next, drag and drop the Headset Alias game object from the hierarchy into the Forward Offset property parameter, as again shown in Figure 10-8. Then, with the Play Area Alias game object expanded in the hierarchy, drag and drop the Headset Origin game object into the Rotation Pivot property parameter, as shown in the figure.
Drag and drop the Scene Cameras game object from the hierarchy into the Scene Cameras property parameter, see Figure 10-8. By default, the rotational snap setting has been set to rotate the player in 45-degree increments with every snap. Leave it at this 45-degree rotation.
Now, playtest your Demo scene using your VR headset with the Camera Rigs , Unity XR setup and your Xbox controller with the Camera Rigs, Spatial Simulator setup. Note that you can slide yourself about by pushing your left controller’s Thumbstick forward and backward. However, with the Free Movement Snap Rotation, you can’t keep your Left Thumbstick continually pushed forward or back, so expect to move it constantly when using it. Next, push your left controller’s Thumbstick to the left or right, and you’ll see that you can snap rotate in 45-degree increments and fade in and fade out with each rotation. You’ll also notice that as you move forward or back, you experience the vignette’s fade-in and fade-out effect .
Summary
In this chapter, we reviewed what seamless locomotion is and how it provides you with immersive movement. We explored the four different ways the VRTK allows you to achieve such movement. We started by learning about VRTKs 1D Axis Action, which provided us with a new way of capturing Horizontal and Vertical Axis input against our Thumbstick. We then went over the Strafing movement mechanism and how to set it up. We also set up the Teleporting animation against the Thumbsticks Horizontal Axis Input and Vertical Axis Input game objects. You learned how to set up Free Movement Smooth Rotation, which you found out causes the most significant motion sickness of all types of movement and rotation. We set up the Free Movement Snap Rotation mechanism, and learned to change the snap rotation value from its default, eliminating the motion sickness encountered with Free Movement Smooth Rotation as a result of its optional fade-in, fade-out effect. We set up the final form of seamless locomotion, which is probably the best method for implementing Free Movement Warp Snap Rotation. Here, in addition to the fade-in, fade-out effect being applied upon every snap rotation, a vignetted fade-in, fade-out effect was also applied upon each forward or backward movement, thereby essentially eliminating motion sickness. You finally learned about the subtle differences between the Free Movement Snap Rotation and the Free Movement Warp Snap Rotation.