Mobile Player Setup (part 3)

Fixing some Bugs

Simon Truong
2 min readNov 15, 2021

--

Continuing from the previous article, we noticed that when Jumping, the boolean for “isGrounded” is still set to true because the update method happens so fast that by the time the character has lifted off from the Jump, the Ray is still hitting the ground. Therefore to remedy this issue we need to create an cool down system that counts down in milliseconds before we can toggle the next jump.

Objective: Create a cool down system to allow the Jumping mechanism be able to happen once only to prevent double jump.

Creating an IEnumerator:

The method in which we will be adding the cool down system would be using Coroutines. Only the Coroutines allow the use of the “Wait for new seconds” function.

First we need to create a new boolean switch variable which controls whenever the jump has been reset. By default this boolean should be set to “false”.

Create an IEnumerator which resets the boolean switch back to false within a new wait for seconds of 0.1 second.

In the “If” statement where you have the input method, we will also add in the Start coroutine function. Along with setting the “ResetJump Boolean” to true.

Finally during the hit collider If statement, we will add in another if statement where the reset Jump boolean is switched to “False” then the “isGrounded” boolean would be set to “True” allowing the ability to jump again.

Save and head back to Unity, now when you jump, there shouldn’t be an ability to double jump until the player has hit the ground again.

--

--

Simon Truong

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