Scripting the Player (Part 3)

Creating the Double Jump

Now that our player can jump and fall at a reasonable pace, we can add a new function called double jump. The logic behind the double jump is very simple and follows the same principle as the regular jump.

Understanding the logic:

In our current script, we have our player jump when we press the space bar then our player falls due to the set gravity. What we want is to basically have the double jump happen before the gravity happens but after we have triggered the initial jump. To accomplish this, we will need to set up a Boolean to check whenever our player is in the air and has started the initial jump. Then and only then, do we allow the player to press the space bar again to have our current Y position be added by another jump variable. Then we set the Boolean for the double jump to false so the player can only do the double jump ONCE per grounded jump.

Scripting the Double Jump:

To start the double jump, I first created another handle for the second jump multiplier. I called this variable “double jump”. I didn’t want to alter the basic jump variable.

Second, I created a Boolean variable which I set the default to “false”. Then I enable the Boolean when the “isGrounded” initial jump is activated.

In the else statement, I use another IF statement to check if another space key was pressed, and if the double Jump was set to true. If those two conditions are met, the player is able to initiate the double jump. I take the yVelocity which houses the current Y position and add in the double jump variable. At the same time, I also set the double jump Boolean back to “false” to limit the double jump to only one time.

If that set, we should be able to create an clean and tight double jump system, if the player is jumping too much, we can adjust the variables within the inspector.

Amazing Double Jump action!

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Designing a Microcontroller Dev Board ft. Clouduino Stratus

From web user to web developer!

Golang Maps vs. Structs, Which Method Should You Use to Parse JSON

Working with SOAP based Web Service using Python

3D FPS Survival Game

Working with pdb in Python

Git commands

How to optimize Firebase Realtime Database calls to improve performance?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Creating a Loot System (part 2)

Using Decals in Unity


3rd Person Controller Using Cinemachine Virtual Camera On Mobile