Reader small image

You're reading from  Unity 2020 Virtual Reality Projects - Third Edition

Product typeBook
Published inJul 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781839217333
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
Jonathan Linowes
Jonathan Linowes
author image
Jonathan Linowes

Jonathan Linowes is a VR/AR enthusiast, Unity, and full stack developer, entrepreneur, certified Unity instructor, and the owner of Parkerhill XR Studio, an immersive media, applications, and game developer. Jonathan has a bachelor of fine arts degree from Syracuse University, a master of science degree from the MIT Media Lab, and has held technical leadership positions at Autodesk and other companies. He has authored multiple books on VR and AR published by Packt Publishing.
Read more about Jonathan Linowes

Right arrow
Teleporting, Locomotion, and Comfort

Up to this point in this book, the player's point-of-view camera has been stationary. In this chapter, we'll start to move around as we consider various mechanics for locomotion and teleportation. Locomotion in Virtual Reality (VR) generally refers to moving around a virtual scene and, specifically, moving in a continuous way. Teleportation refers to moving to a new location in a single discrete jump. Both of these techniques are compatible with stationary and room-scale tracking. In stationary tracking, locomotion and teleportation are the only means for moving within the scene.

In room-scale tracking, the player can physically walk around the scene within the bounds of the play space, yet can also use locomotion and teleportation to move to a new location. In that case, the play space origin itself (for example, XR Rig) is moved, as we'll see in the various examples...

Technical requirements

To implement the projects and exercises in this chapter, you will need the following:

  • A PC or Mac with Unity 2019.4 LTS or later, an XR Plugin for your device, and the XR Interaction Toolkit installed
  • A VR headset supported by the Unity XR Platform

You can access or clone the GitHub repository for this book (https://github.com/PacktPublishing/Unity-2020-Virtual-Reality-Projects-3rd-Edition-) to optionally use assets and completed projects for this chapter, as follows:

  • Asset files for you to use in this chapter are located in UVRP3Files/Chapter-07-Files.zip.
  • All completed projects in this book are in a single Unity project atUVRP3Projects.
  • The completed assets and scenes for this chapter are in theUVRP3Projects/Assets/_UVRP3Assets/Chapter07/folder.

Implementing basic glide locomotion

Locomotion refers to moving around the scene in a continuous way. In this first example, we'll implement a basic glide locomotion mechanic using the thumbstick on your hand controller to move you in a given direction. We'll start with moving forward (and backward) with a vertical push of the thumbstick. There are several ways you can decide what "forward" means, either based on the direction the player is looking (camera forward direction) or based on the direction the hand controller is pointing, or by using the horizontal press of the thumbstick to rotate. Our script will support all these options: camera forward, hand forward, and thumbstick rotate.

Caution is advised when using glide locomotion in VR as it can cause motion sickness in some players. For this reason, teleportation is often the preferred mechanism in VR. This can be mitigated, for example, if the player is driving "inside" a vehicle because...

Climbing a wall

Many VR games include the ability to climb a wall or ladder; that is, locomotion in a vertical direction. In this section, we will implement a wall-climbing exercise using a hand-over-hand grab-and-pull mechanic. Given a climbing wall, the player can reach up and grab a hold, then pull themself up, reach with the other hand to grab another hold, and so on. But if you let go with both hands, you'll fall! For this, we're going the use the XRI Toolkit's Interactor and Interactable components. We'll build a wall with a series of GrabHold prefabs. Then, we'll write two scripts. A GrabPull script notifies the ClimbController when the player has grabbed or released a hold. The ClimbController moves the XR Rig, and it detects when the player has completely let go, causing them to fall.

Begin with a basic scene such as the one defined at the top of this chapter, as follows:

  1. Open the scene by clicking File | Open Scene...

Using the XRI Locomotion System

The Unity XR Interaction Toolkit includes what they call the Locomotion System, a framework for managing the relocation of the player rig at runtime. They use the word Locomotion to encompass both teleportation and my narrower definition of locomotion. By my definition, locomotion refers to a smooth movement of the player in the scene, whereas teleportation refers to a discrete jump from one location to another. The XRI Locomotion System has an architecture that can be extended with custom Locomotion Providers, some of which they provide, and others you can write, such as the GlideLocomotion and ClimbController components we developed earlier in this chapter.

In this section, we will introduce the architecture of the XRI Locomotion System, Locomotion Providers, and its control-locking protocol for managing user interactions. We will then install the XRI examples assets, provided separately by Unity, into our project.

Understanding...

Teleporting between locations

Teleportation is a type of locomotion that teleports the user from one position to another position, in discrete jumps rather than a continuous gliding motion. Teleportation is generally more user-friendly in VR, reduces the risk of motion sickness, and is often more convenient to use. Normally, as a developer, you designate specific locations or areas where the player is allowed to go. The player then uses the hand controller to point at and select a target location and triggers a jump from here to there. The selection is often indicated with a glowing laser arc ray and a glowing teleportation location disk, showing where the player will end up.

To implement teleportation in our scene, we will use components included with the XRI Toolkit package, but we also need graphics for the arc laser and location anchors effects. For this, it'll be easier to use some of the assets included with the XR Interaction Toolkit Examples project, so let...

Locomotion and comfort in VR

Locomotion and teleportation in VR is not a settled science. Many techniques have been tried; some have proven successful and represent best practices. We've demonstrated some of these in this chapter. Others have failed and are discouraged. New advancements in hardware, software, and player mechanics keep the options fresh and open to innovation. In this section, I present a bagful of ideas, in no particular order, for your consideration and amusement, including other locomotion mechanics and techniques for managing VR motion sickness.

Other locomotion mechanics

In the first edition of this book (2015), we implemented a game where you could ride an "elevator" to a high platform, and then jump off onto a trampoline. You'd hit the trampoline, bounce up, and down, bounce up again, and down until you settled. I assumed that would be really fun in VR, but it turned out to be a really bad idea! Unless you want to invoke...

Summary

In this chapter, we explored a variety of mechanics for moving the player within your virtual environments. We started by implementing a glide locomotion mechanic, using the thumbstick on the hand controller to drive through the scene. This included alternative ways to define what "moving forward" means, using the gaze direction, pointing with a hand controller, or rotating using the horizontal axis of the thumb controller. Then, we built a climbing wall using a hand-over-hand grab-and-pull mechanic. We even made the player fall to the ground if they let go!

We also learned about the XR Interaction Toolkit's Locomotion System that uses Locomotion Providers to implement various features. First, we added a Snap Turn Provider to turn the player in discrete angle increments with the thumbstick, and we learned to use the XRI API to integrate our own GlideLocomotion script with the Locomotion System. Next, we implemented teleportation using a Teleportation...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Unity 2020 Virtual Reality Projects - Third Edition
Published in: Jul 2020Publisher: PacktISBN-13: 9781839217333
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Jonathan Linowes

Jonathan Linowes is a VR/AR enthusiast, Unity, and full stack developer, entrepreneur, certified Unity instructor, and the owner of Parkerhill XR Studio, an immersive media, applications, and game developer. Jonathan has a bachelor of fine arts degree from Syracuse University, a master of science degree from the MIT Media Lab, and has held technical leadership positions at Autodesk and other companies. He has authored multiple books on VR and AR published by Packt Publishing.
Read more about Jonathan Linowes