© 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_12

12. Setting Up a Pseudo-Body

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

In the last two chapters on seamless locomotion and arm-swinging movement, you probably noticed that you could easily pass through the solid containers, barrels, ladder, and table available in the Demo scene. In most cases, you wouldn’t want such behavior to happen though. Ideally, you want yourself to be stopped the moment you collide with a solid object. All barrels, containers, ladder, and tables have been fitted with colliders that aren’t Triggers. However, you can still pass through these objects. To ensure that this doesn’t happen, you will need to set up a pseudo-body. This chapter is dedicated to setting up this pseudo-body to enforce the Plausibility Illusion, wherein you cannot pass through solid objects. We will also review a commonly used technique wherein the player’s headset fades to black upon their head colliding with a solid object.

Advantages of Having a Pseudo-Body

A pseudo-body allows you to provide a virtual presence for the position of your real-world body in a spatial scene. You can also apply in-game physics to your pseudo-body, which will enable you to climb a ladder and walk up steps as well as fall from heights.

The pseudo-body creates a Rigidbody that tracks your real-world head position and translates it into your spatial environment. Your pseudo-body needs to be set up in such a way that it provides you the ability to prevent yourself from passing through solid objects and ensures that your prototype hands and Oculus-provided hands as well as interactors don’t collide with it. If a collision does occur between your pseudo-body and these objects, it will result in weird movement behavior. Let’s begin setting up this pseudo-body and configure it in a manner that lives up to the requirements just discussed.

Pseudo-Body Setup

In the hierarchy, select the VRTK SETUP game object and create an empty child game object within it and rename it to “VRTK PSEUDOBODY.”

Then, select the Project tab and expand the “Packages” folder. Locate the Tilia Trackers Pseudo-Body Unity package and expand it until you reach its “Prefabs” folder. From the pane on the right, drag and drop the Trackers Pseudo-Body prefab onto the VRTK PSEUDOBODY game object in the hierarchy and select it. Set the Layer for this Trackers Pseudo-Body game object to Ignore Ray Cast. When prompted to set the Layer to ignore ray cast for all child objects, click Yes, Change Children.

This ensures that your pseudo-body will not collide with the Interactable objects you grab. You’ll recall that all Interactable objects in your Demo scene need their Layer set to Interactable.

Also, if you look at your Layer Collision Matrix, as shown in Figure 12-1, you’ll notice that you’ve disabled collisions between Layers, Interactable, and Ignore Ray Cast. This ensures that a collision will never occur between your pseudo-body and the grabbed object in your hand as long as this grabbed object layer has been set to Interactable.
Figure 12-1

Layer Collision Matrix setup thus far

It’s important to note that you should avoid all external collisions with your pseudo-body. The pseudo-body follows your headset, and any external collision that take place while it’s in motion will result in weird movement behavior.

Let’s now set up the Source and Offset properties for your pseudo-body. These are available in the Pseudo-Body Facade component of the “Tracking Settings” section in the Inspector.

The Source property determines which game object your pseudo-body should follow. Your headset and controllers are the objects that are tracked and move about in the real world, so it’s appropriate that you have your pseudo-body follow your headset.

Drag and drop the Headset Alias game object from the hierarchy into the Source property parameter of the Pseudo-Body Facade component. Now, whenever your headset moves in the real world, your pseudo-body will follow it.

The Offset property is an optional positional offset that can be used by the Source when it is not centered, such as when the headset is not centered within the Play Area. Thus, if you as the player are not standing in the center of the Play Area, this Offset will be used in computing your optimal location.

Drag and drop the Play Area Alias game object from the hierarchy into the Offset property parameter.

Now, let’s turn our attention to the “Interaction Settings” section. Here, you need to specify the Interactors that the pseudo-body should ignore. You have two Interactors in your Demo scene. Expand Elements located beneath Ignored Game Object and set its size to 2. You’ll see that two element slots are made available.

From the hierarchy, drag and drop the Interactions Interactor Left game object into the Element 0 slot. Then, drag and drop the Interactions Interactor Right game object into the Element 1 slot. Figure 12-2 displays these settings against the pseudo-body component.
Figure 12-2

Setting up the Trackers Pseudo-Body

Playtest your scene using the Camera Rigs, Spatial Simulator along with the keyboard. Using the W key, walk forward toward the container in front of you. You’ll see that you can still pass through this solid container fitted with a box collider. Finally, stop your Demo scene from playing.

Implementing a Rollback Mechanic

There are two ways that you can prevent yourself from passing through solid objects. The preferred method is to force your position to be rolled back to where the pseudo-body’s collider is located whenever a divergence occurs between your headset and the pseudo-body’s collider. We’ll look at setting up this method first. The other, more straightforward solution is to fade your headset view to black whenever your head collides with a solid object within the VR world.

Ensure that the Gizmos button within Unity’s editor has been toggled on. Playtest your scene using the Camera Rigs, Spatial Simulator again. Then, using the W key, walk forward toward the container in front of you. Ensure that you push your hands through the container.

Now, switch to the Scene tab in Unity’s editor. Double-click the Trackers Pseudo-Body game object in the hierarchy to allow it to obtain focus. As shown in Figure 12-3, your headset (camera) and hands have diverged from your pseudo-body. The green capsule outline you see in the figure represents your pseudo-body’s collider that has been stopped from colliding with the container while you are in it. Your headset (represented by the camera gizmo icon) along with your hands have passed through the container. You can walk into the container; however, your pseudo-body won’t follow you into the container. Here is a situation where a divergence has occurred between your headset and your pseudo-body. When this happens, all that needs to be done is that your position needs to be rolled back to the location of the pseudo-body’s collider. It’s essential to see what this divergence looks like visually, as depicted in Figure 12-3, so that you can understand how to go about using the pseudo-body to prevent yourself from penetrating through the container.
Figure 12-3

A divergence between your pseudo-body and your headset and hands

In the event you don’t see the pseudo-body collider, you can enable it as follows: From within the hierarchy, select and expand the Trackers Pseudo-Body game object. Next, expand the Collidable Volume game object and select the Child Collider game object within it. Then, in the Capsule Collider component of the Inspector, click the Edit Collider button to turn on the Capsule Collider.

To set up this Rollback mechanic, you first need to set up some Body Events, which are crucial to ensuring that you can’t pass through solid objects. They also ensure that no weird collision behavior arises when attempting to climb any object in your virtual world.

With the Trackers Pseudo-Body game object selected in the hierarchy, and its pseudo-body component expanded, locate and expand the Still Diverged event in the “Body Events” section. This event will be used to solve the divergence issue wherein the headset remains diverged from the pseudo-body.

Whenever your headset has diverged from your pseudo-body, the Still Diverged event will be triggered, essentially letting you know that the divergence has occurred. When this event fires, you need to ensure that you roll back your position to where the pseudo-body collider is located, thereby forcing yourself out of the container. Whenever this event is fired, it is easily achievable by calling upon the Solve Body Collisions method, available against the pseudo-body via its Pseudo-Body Facade component.

Let’s set up this event now. With the Still Diverged event expanded in the Inspector, click the plus symbol in the bottom right corner to add an event listener. Drag and drop the Trackers Pseudo-Body game object from the hierarchy into the event listener box of the Still Diverged event. For the function, select Pseudo-Body Facade, Solve Body Collisions.

This ensures that the moment your headset and pseudo-body have diverged, the Still Diverged event will be triggered, which in turn calls the Solve Body Collisions method, resulting in your position being rolled back to the location of the pseudo-body collider. By doing this, you no longer can enter a solid object. Figure 12-4 shows the Still Diverged event set up against your Trackers Pseudo-Body game object.
Figure 12-4

Setting up the Still Diverged( ) event to solve for body collisions (effecting a rollback) when a divergence occurs

Before we begin testing our Demo scene, we need to ensure that our prototype hands and Oculus-provided hands don’t collide with our pseudo-body. We’ve already made sure that the pseudo-body will ignore both of our Interactors by setting them up as part of the Ignored Game Objects Elements in the Pseudo-Body Facade component.

Now, let’s increase this Ignored Game Objects element’s size to 6. We’ll next add our Hand Proto Left and Hand Proto Right and Oculus-provided Custom Hand Left and Custom Hand Right as game objects that need to be ignored by the pseudo-body.

Drag and drop the Hand Proto Left and Hand Proto Right as well as the Oculus-provided Left and Right Custom Hands into the four new element slots you created as follows:
  1. 1.

    Drag and drop Custom Hand Left into the Element 2 slot.

     
  2. 2.

    Drag and drop Hand Proto Left into the Element 3 slot.

     
  3. 3.

    Drag and drop Custom Hand Right into the Element 4 slot.

     
  4. 4.

    Drag and drop Hand Proto Right into the Element 5 slot.

     
Any object you don’t want colliding with the pseudo-body can be added to this Ignored Game Objects list, see Figure 12-5.
Figure 12-5

Completing the setup of the Trackers Pseudo-Body

Now, playtest your Demo scene using your VR headset with the Camera Rigs, Unity XR setup. Note that you won’t be able to pass through the containers or barrels. As you attempt to pass through any of these solid objects, you’ll find yourself being pushed back. Divergence is being resolved here via the Solve Body Collisions method.

Using a form of slide locomotion, approach the ladder and push your Thumbstick forward. You’ll see that you can ascend the ladder and climb to the top of the container. Now, approach the edge of the container, and if you’re wearing your VR headset, take that leap of faith and jump, or if using your Xbox controller, push forward on the Thumbstick, and you’ll find that you can jump off the container using the controller as well.

Last, try having your hands interact with your pseudo-body. You should find no weird behavior. Grab the Drill machine on the table and push it toward your pseudo-body. You won’t find any weird behavior here either. Note that the Layer for the Drill machine had been set to Interactable.

Fading the Headset View to Black on Collision

VRTK provides you with a Collision Fader prefab that detects when the player’s VR headset collides with another game object, fading the screen to a solid color when that happens. This solves the issue wherein players can push their head through a game object and see the inside clipping area, which is an undesired effect. The reasoning behind this is that if the player pushes their head through an object where it shouldn’t be, then fading to a color (e.g., black) will make the player realize they’ve done something wrong and they’ll probably step backward naturally. However, one disadvantage of fading to black is that the player can continue to push forward through the solid object. Hence, this Collision Fader prefab is best used in conjunction with the pseudo-body’s rollback mechanic. Again, this depends on what you want to achieve in your game.

Before setting up this headset collision fade mechanic, select the VRTK PSEUDOBODY game object in the hierarchy and deactivate it. You’ll first test the headset collision fade mechanic without having the rollback mechanic set up against the pseudo-body. Later, you’ll activate the VRTK PSEUDOBODY game object to see how you can have both mechanics function together, which could be the effect you desire.

Let’s now begin setting up this headset collision fade mechanic. In the hierarchy, select the VRTK SETUP game object and create a new empty game object within it. Rename the child game object “VRTK HEADSET COLLISION FADE.”

Select the Project tab and expand the “Packages” folder. Locate the Tilia Visuals Collision Fader Unity package and expand it until you reach its “Prefabs” folder. Drag and drop the Visuals Collision Fader prefab you see in the right-hand pane onto the VRTK HEADSET COLLISION FADE game object in the hierarchy.

With the Visuals, Collision Fader game object selected in the hierarchy, ensure that its Collision Fader Facade component has been expanded in the Inspector. You need to set up several properties in the “Tracking Settings” section to get the Collision Fader working. For the Source property, drag and drop the Headset Alias game object from within the Camera Rigs, Tracked Alias game object into the Source property parameter, as shown in Figure 12-6. The Source property needs to be set to your Headset Alias, as you want your screen to fade to black when the player pushes their head through a solid object like one of the containers you have in the Demo scene.

For the Camera Validity property , drag and drop the Scene Cameras game object into this property parameter. This lets the Collision Fader know which cameras the fade should be applied against.

Last, the Collision Validity property requires you to set up a rule to determine which objects in the scene will activate a fade to black. You’ll have your headset fade to black only when you attempt to push your head through any of the containers within the Demo scene.

Let’s first create a new layer that will be applied to all containers within the Demo scene. We’ll call this layer “WorldStaticMeshes.” From the Unity Editor’s main menu, navigate to Edit ➤ Project Settings ➤ Tags and Layers. From within the Tags and Layers pane available on the right, expand the Layers drop-down and locate the first-available empty User Layer. Type “WorldStaticMeshes” into the text box on the right. Finally, close the Project Settings dialog box.

Now, select the Environment game object in the hierarchy, and then select and expand its Containers child game object. You’ll see that each of the containers has its Layer set to Default. Select all nine Container game objects that are children of the main Containers game object. In the Inspector, expand the Layer drop-down and select the layer WorldStaticMeshes. This ensures that each Container game object within the Demo scene will be assigned this layer.

You can now create a Collision Fader rule using the Any Layer Rule component that has its Layer Mask set to WorldStaticMeshes and apply this rule to the Collision Validity property. By doing this, when your headset collides with any Container game object in the scene, the Collision Validity property emits a True value, kicking the fade into a black effect.

In the hierarchy, select and expand the Rules game object. Create a new empty child game object within it and rename it “Headset Collision Fader.” With this game object selected in the hierarchy, click the Add Component button in the Inspector and add the Any Layer Rule component. With this expanded, set its Layer Mask property to WorldStaticMeshes.

Select the Visuals Collision Fader game object in the hierarchy. Drag and drop the Headset Collision Fader rule game object into its Collision Validity property parameter.

You have now completed the setup for the Visuals Collision Fader game object, see Figure 12-6.
Figure 12-6

Setting up the Visuals Collision Fader game object

Test your Demo scene using your VR headset with the Camera Rigs, Unity XR setup or the Camera Rigs, Oculus Integration setup . The one you choose to use will depend upon which headset you’re using. Approach any container in your VR world and try pushing your head through it. You’ll see that your headset screen immediately fades to black.

With one of the seamless forms of locomotion active, push forward against your VR controller’s Left Thumbstick for a few seconds and you’ll see that you pass through the container and exit on the opposite side. Even though your headset view fades to black when your head is pushed through the container, nothing is stopping the player from pushing themselves forward. This may be the effect you desire, but probably not. You may not want your player to be able to enter a solid object like a container. The pseudo-body you set up in the last section (Pseudo-Body Setup) can help out here.

Select the VRTK PSEUDOBODY game object in the hierarchy and activate it. Now, playtest your Demo scene again. Approach any container in your VR world and try pushing your head through it. You’ll find that your headset screen immediately fades to black. While your headset is faded to black, push forward against the Left Thumbstick of your VR controller, attempting to pass right through the container and exit on the opposite side. Notice that it is not possible to pass through the container. This is because the pseudo-body rollback mechanic you set up is now in play. The moment a divergence occurs, you are rolled back. Also, having set up the Collision Fader component, your headset view fades to black, a visual cue that the object is impenetrable. Most paid VR frameworks available in the Unity Asset store don’t provide you with this sort of a rollback mechanic, which helps with plausibility illusion in your VR worlds.

Summary

In this chapter, we reviewed a fundamental concept, the pseudo-body. Almost any experience or game you create will definitely require this pseudo-body to enhance the Plausibility Illusion. Before setting up this pseudo-body, you saw that it was possible to pass through solid objects in your Demo scene, which is not what you want to happen in your VR world. Setting up a pseudo-body helped eliminate this strange behavior.

We first went over the advantages associated with having a pseudo-body. We then set up a pseudo-body. You learned to configure the properties available against your Pseudo-Body Facade component. We then took a deep dive into understanding how the rollback mechanic works with the pseudo-body, preventing the player from passing through solid objects.

You learned about the concept of divergence and how to set up the Still Diverged event to facilitate the rollback mechanic. Finally, you learned about the headset collision fade mechanic, which is commonly used to create the illusion of solid objects being impenetrable. You also learned about the downside of this approach. You then learned how to use the Collision Fader in conjunction with the pseudo-body to achieve the best of both worlds.

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

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