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

11. Arm-Swinging Movement

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

Teleporting and seamless locomotion are excellent. However, in certain situations, allowing players to swing their arms as they move can increase immersion, as in the real world doing this is as natural as walking. It allows the player to decide how fast they want to move and allows for small, accurate movements. If you were creating an endless runner game in VR, arm swinging would create a truly immersive and natural experience of moving. In this chapter, we’ll see how to set up an arm-swinging locomotion technique that we can use as we get moving in the VR world. Note that this aspect of locomotion isn’t provided in most VR frameworks that you purchase from the Unity Asset store.

Move in Place Locomotion

Arm-swinging movement is more commonly referred to as Move in Place locomotion. To get this arm-swinging movement working, you’ve been provided with a prefab that you need to set up. However, note that it was a member of the VRTK community who provided this prefab. As such, it exists as a different scope within the npmjs scoped registry. You can view this scoped registry by navigating to Edit ➤ Project Settings ➤ Package Manager.

Capturing Thumbstick Touch Input

Before configuring the Move in Place game object, we need to set up two intermediary game objects, one for each hand, that can be used to determine when an arm swing occurs. We’ll enable the Move in Place movement to happen only when the Left or Right Thumbstick is being touched. The two intermediary game objects you’ll create will need to explicitly test for a Thumbstick touch action occurring on either the Left or Right Thumbstick of your VR controllers. We’ll test for this Thumbstick touch occurring only against your HTC Vive and Oculus devices only, not against the XBox controller.

To set this up, select and expand the Button Input Actions game object in the hierarchy, and create two new empty child game objects within it. Select the first newly created empty child game object and rename it “Left Hand Thumbstick Touch.” Then, select the second newly created empty child game object and rename it “Right Hand Thumbstick Touch.”

Select both the Left Hand Thumbstick Touch and Right Hand Thumbstick Touch game objects in the hierarchy. Click the Add Component button and add a Boolean Action component to both of these game objects in the Inspector. Ensure that the Boolean Action component is expanded. Expand Sources, and set its size to 2. You now have two element slots available.

Now, select just the Left Hand Thumbstick Touch game object in the hierarchy. Then, drag and drop the Oculus Left Thumbstick Touch 16 game object from the hierarchy into the Element 0 slot. Next, drag and drop the Open VR Left Trackpad Touch 16 game object from the hierarchy into the Element 1 slot.

Your Left Thumbstick Touch button action for your Oculus and HTC Vive controllers has now been set up, see Figure 11-1.
Figure 11-1

Setting up the Left Hand Thumbstick Touch intermediary game object to capture the HTC Vive and Oculus VR controllers Left Thumbstick touch input

Now, select just the Right Hand Thumbstick Touch game object in the hierarchy. Drag and drop the Oculus Right Thumbstick Touch 17 game object from the hierarchy into the Element 0 slot. Next, drag and drop the Open VR Right Trackpad Touch 17 game object from the hierarchy into the Element 1 slot. This sets up the Right Thumbstick Touch button action for your Oculus and HTC Vive controllers, see Figure 11-2.
Figure 11-2

Setting up the Right Hand Thumbstick Touch intermediary game object to capture the HTC Vive and Oculus VR controllers Right Thumbstick touch input

Setting Up the Move in Place Locomotion

Let’s now set up the Move in Place locomotion mechanic within our Demo scene. We’ll set up this Arm-Swinging Locomotion to work with our VR controllers only, not with the XBox controller, as it doesn’t make sense to swing the XBox controller.

With your Demo scene open, select the VRTK SETUP game object in the hierarchy, and create a new empty child game object within it and rename it “VRTK MOVE IN PLACE.” Next, select the Project tab, and expand the “Packages” folder until you locate the Fight 4 Dream Locomotors Move in Place, Unity package. Expand this folder until you reach its “Prefabs” folder, in the right pane of which you’ll notice the Move in Place prefab. Drag and drop this prefab onto the VRTK MOVE IN PLACE game object in the hierarchy.

Select the Move in Place game object in the hierarchy and ensure that the Move in Place component has been expanded within the Inspector .

You now need to set up several properties within this Move in Place component. Drag and drop the Left Hand Thumbstick Touch game object from the hierarchy into the Left Controller Action property parameter of the Move in Place component. Then, drag and drop the Right Hand Thumbstick Touch game object from the hierarchy into the Right Controller Action property parameter of the same component.

These settings enable the Move in Place component to listen for a Thumbstick touch occurring on either the right or left controller, see Figure 11-3.
Figure 11-3

Setting up the Move in Place game object to listen for a Thumbstick touch occurring against either the right or left controller

As discussed in Chapter 7, your Left and Right Controller Aliases are fitted with Velocity Tracker Processor components . The Move in Place game object previously displayed requires its Left and Right Controller Velocity Tracker properties to be populated. You’ll populate these properties with the Left and Right controller Alias game objects located within the Camera Rigs, Tracked Alias game object.

Expand the Camera Rigs, Tracked Alias, and then expand its Aliases game object. Drag and drop the Left Controller Alias from the hierarchy into the Left Controller Velocity Tracker property parameter. Next, drag and drop the Right Controller Alias from within the hierarchy into the Right Controller Velocity Tracker property parameter, as shown in Figure 11-4.

Next, expand the “Elements” section, available beneath Forward Sources, and set its size to 1 to have an Element 0 slot made available. Here, you need to specify 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 this Element 0 slot, as shown in Figure 11-4.

The Target property determines which object will slide around in the Demo scene. As you want to move within the Demo scene, you need to set this property to the Play Area Alias. Drag and drop the Play Area Alias game object from the hierarchy into the Target property parameter, as shown in Figure 11-4.

Now, set the Speed Multiplier property value to 1.5. You can tweak this value depending upon the speed at which you want to move. Also, set the Speed Threshold value to 0.1. Last, set the Drag value to 1. You may want to tweak this value as well so that your player comes to a halt quicker, see Figure 11-4.
Figure 11-4

Setting up the remaining properties for the Move in Place game object

You have now completed your Arm-Swinging Locomotion setup, and it’s time to test it out. Playtest your scene using your VR headset along with the Camera Rigs, Unity XR setup to give the Move in Place locomotion a try.

Touch your left or right controller to swing your arms back and forth, like you do when walking. The faster you move your arms, the faster you’ll move forward in the VR world. Note that you only need to touch your Thumbsticks; you don’t need to press them in.

While swinging your arms back and forth, look in the direction you want to go and the direction of your movement will change accordingly. Touch the Thumbstick of only one controller to move only that arm back and forth. You can try this out against your right controller. You’ll see that you can move even by swinging just one arm.

You have now created a fantastic form of real-life movement.

Summary

In this chapter, we learned what Move in Place locomotion is and how it provides you with immersive true-to-life movement. We set up two intermediary game objects to capture Thumbstick touch input against our left and right controllers. We then set up the Move in Place locomotion prefab that enabled our arm-swinging locomotion to work. You saw that by just swinging one arm, you were able to move within your VR world. Finally, you tested out this new locomotion mechanism using your VR headset.

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

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