Jumping
When we created the trampoline, I mentioned that our implementation doesn't require you to jump to start bouncing. However, jumping is a fun idea, whether on a trampoline or not. Some games use the keyboard spacebar or a controller button to make your avatar jump. We'll now implement a simple jump gesture from the VR headset, which applies a vertical velocity to our movement.
Note
Note that this will not work with headsets that lack positional tracking, such as Google Cardboard and GearVR.
Feature: When I jump, my character in VR jumps.
To implement a jump gesture, we'll look for a rapid change in the Y position of the headset, which is very similar to the head nod gesture that we did in Chapter 5, World Space UI, (which checked for a rapid change in the x-axis angle). When a jump gesture is detected, we'll apply a vertical force to the first-person , as follows:
With
MeMyselfEye
selected in Hierarchy, create the script by navigating to Add Component | New Script.Name it
JumpGesture...