The ability to climb up objects, Tomb Raider style, to get to your destination is one of the most enthralling things you can do in VR. The VRTK makes climbing a breeze, allowing you to make almost any surface climbable. Need to climb a fence, a ladder, or perhaps a wall, no worries. This climbing mechanic can be easily created using a customized Interactable prefab that handles the climbing action in conjunction with the pseudo-body to handle the physics of the player’s body. In this chapter, we’ll make all Containers and the Ladder in our Demo scene climbable.
Climbing Mechanic Requirements
The VRTK provides you with two prefabs that are necessary to set up a climbing mechanic. To set up this climbing mechanic against game objects within your Demo scene, you’ll first require a Climbing Controller, whose responsibility is to communicate with the pseudo-body you already set up. You’ll also need a unique Climbable Interactable object that an Interactor can grab, which will serve as the foundation for your climbable object. Let’s begin by setting up the Climbing Controller.
Setting Up the Climbing Controller
To start, select the VRTK SETUP game object from within the hierarchy, and create an empty child game object and rename it “VRTK CLIMBING.”
Then, select and expand the “Packages” folder from within the Project tab. Locate the Tilia Locomotors Climbing Unity package and expand it until you reach its “Prefabs” folder. Drag and drop the Locomotors Climbing prefab available in the right-hand pane onto the VRTK CLIMBING game object in the hierarchy.
Within the Demo scene, you’ll convert all Containers and the Ladder into climbable objects. To achieve this, the VRTK provides you with an Interactions Climbable prefab that an Interactor can grab. To make these objects climbable, you’ll need to add this Interactions Climbable prefab to each Container and the Ladder within the Demo scene.
Making the Containers Climbable
You’ll notice that the Demo scene has nine Containers in it, each of which has an appropriate Mesh and is fitted with a Box Collider. You’ll also notice that all these Containers have already been placed at strategic locations in the scene. You don’t want to change the position of these Container game objects when setting them up as climbable objects.
To make a Container climbable, all you need to do is swap out the Cube game object shown in Figure 13-2 with your Container game object, which already contains a Mesh and box collider. For each Container you want to make climbable, you need to have a corresponding Interactions Climbable game object in the scene, so that its Cube game object can be swapped out with the concerned Container game object. For the Demo scene, this would mean you require nine Interactions Climbable game objects.
The procedure applied here is similar to the one you used when you swapped out your Interactable Cube for the Drill machine. Looking at Figure 13-2, you’ll see that the Interactions Climbable game object has an Interactions Interactable nested in it. This is the same Interactable that allowed you to grab the Drill machine.
Now, select the first Interactions Climbable game object in the hierarchy. Ensure that the Transform component in the Inspector has been expanded, and then expand the context menu for its Transform component by clicking the three vertical dots to the right of its Transform component heading. Then, select the Paste Component Values menu item, as shown in Figure 13-5.
Now, expand this Interactions Climbable game object in the hierarchy until you reach its Cube game object, which is nested within the Mesh Container game object. This is depicted in Figure 13-2. Deactivate this Cube game object, as you want your Container game object to become the actual Mesh.
Once you’ve set up all nine Container objects to be climbable, select all of them in the hierarchy. Then, drag and drop them onto the Containers game object in the Environment game object. With all nine Containers still selected in the hierarchy, ensure that their Climbable Facade component has been expanded in the Inspector. Now, drag and drop the Locomotors Climbing game object from the hierarchy into the Climbing Facade property parameter. This connects each of your nine climbable Container game objects to the Locomotors Climbing controller, see Figure 13-7.
Making the Ladder Climbable
Let’s now set up your Ladder to be climbable. The procedure is similar to the one you used for making your Containers climbable. You’ll notice that your Ladder comprises two objects: Steel Ladder A and Steel Ladder B, each of them having its own Mesh and colliders. The Ladder game object is located in the hierarchy in the Environment game object. To set up this Ladder, you’ll need two Interactions Climbable prefabs, one for setting up Steel Ladder A to be climbable and the other for setting up Steel Ladder B similarly.
You should still have the “Prefabs” folder selected in your Tilia Locomotors Climbing Unity package. Drag and drop the Interactions Climbable prefab in the right-hand pane onto the Ladder game object in the hierarchy, and rename it “Interactions Climbable Steel Ladder A.” Then, duplicate this steel ladder and rename it “Interactions Climbable Steel Ladder B.”
Select both Interactions Climbable Steel Ladders in the hierarchy, and within the Inspector, ensure that their Climbable Facade components have been expanded. Drag and drop the Locomotors Climbing Controller game object from the hierarchy into the Climbing Facade property parameter.
Last, select the Steel Ladder A game object that is now a child of the Mesh Container and reset its Transform. We now need to set up Steel Ladder B using the same procedure we used for Steel Ladder A.
Deactivating Untouched Events on Climbable Game Objects
While climbing up any climbable object, you may find yourself falling for no apparent reason. This behavior may happen when you have your pseudo-body solving for body collisions during a climb. When pulling yourself up a Container, your pseudo-body will attempt to solve the body collision with the Container upon colliding with it. If you happen to let go of your grab at the same time, the Ungrab on Untouch Process attached to the Untouched event will be activated, as discussed later in the chapter, causing you to fall unexpectedly. There are a couple of ways to solve this issue. Let’s adopt the most straightforward approach.
Finally, you need to turn off this Untouched event for the Interactions Climbable Steel Ladder B game object, as well as for all nine climbable Container game objects in the Demo scene.
Now, playtest the climbable mechanic you’ve set up in the Demo scene. Climb up a couple of Containers as well as the Ladder, and you’ll notice that while climbing, you may encounter some jittering. Go ahead and try this out now.
Go ahead and try out your climbing mechanic now to ensure you don’t experience any unexpected falling behavior or jittering while climbing.
You have now created an extremely sophisticated climbing mechanic and can easily climb any climbable object Tomb Raider style.
Summary
In this chapter, we learned how to set up climbing in VR using the VRTK’s provided prefabs. We started by setting up a Locomotors Climbing controller game object responsible for communicating with our pseudo-body during a climb. We then explored the Interactions Climbable prefab and learned how to set it up against each of the nine available Containers in the Demo scene. We next hooked up our Locomotors Climbing controller to each of our climbable Containers using the Climbing Facade property in the Climbable Facade component of our Climbable Container game objects. We used the same procedure to enable the Ladder to be climbable.
Finally, we went over a particular unexpected falling behavior that could occur while climbing on account of our pseudo-body attempting to solve for body collisions. To eliminate this possible falling behavior, we deactivated the Untouched event located within each climbable object’s Interactions Interactable game object. We also learned that by assigning our Ladder and Containers to the Ignore Raycast layer, we could eliminate any jittering that occurs while climbing.