Unity in Action by Joseph Hocking;

Unity in Action by Joseph Hocking;

Author:Joseph Hocking; [Hocking, Joseph]
Language: eng
Format: epub
ISBN: 9781617294969
Publisher: Simon & Schuster
Published: 2018-03-28T00:00:00+00:00


8.3 Implementing the jump action

In the previous section you wrote code to make the character run around on the ground. In the chapter introduction, I also mentioned making the character jump, so let’s do that now. Most third-person games do have a control for jumping. And even if they don’t, they almost always have vertical movement from the character falling off ledges. Our code will handle both jumping and falling. Specifically, this code will have gravity pulling the player down at all times, but occasionally an upward jolt will be applied when the player jumps.

Before you write this code, let’s add a few raised platforms to the scene. There’s currently nothing to jump on or fall off of! Create a couple more cube objects, and then modify their positions and scale to give the player platforms to jump on. In the sample project, I added two cubes and used these settings: Position 5, .75, 5 and Scale 4, 1.5, 4; Position 1, 1.5, 5.5 and Scale 4, 3, 4. Figure 8.8 shows the raised platforms.

Figure 8.8 A couple of raised platforms added to the sparse scene



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.