From the course: Advanced Unity 2D: Platformer Player Movement

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Limiting jump

Limiting jump - Unity Tutorial

From the course: Advanced Unity 2D: Platformer Player Movement

Start my 1-month free trial

Limiting jump

- Now we're ready to fix the bug we saw in the previous video, where if you hold down the jump key, the player just keeps jumping. In order to do that, we're going to want to keep track of the time the jump key has been pressed. If it's closer to zero, we know that it's recently been released. If not, we know that it's being held down for a longer period of time. In order to do that, we're going to have to create a new method on the input state, that gives us access to the button hold time that we're tracking. Let's open up the input state class, and at the bottom, we're going to copy the get button value method and paste it below. Let's change this to get button hold time, and we're going to want to change the return value to a float. Next, we'll want to get the whole time property on the state, and finally, if no button state exists, we're going to want to return zero as the value. Now, we'll save this script, and let's go back into our jump script. At this point, we're going to…

Contents