Get Kids into Coding with Scratch

# Preventing Double Jumps

## Steve Kinney

Temporal

### Check out a free preview of the full Get Kids into Coding with Scratch course

The "Preventing Double Jumps" Lesson is part of the full, Get Kids into Coding with Scratch course featured in this preview video. Here's what you'd learn in this lesson:

Steve updates the jump movement to include velocity and prevent double jumping.

Preview
Close

### Transcript from the "Preventing Double Jumps" Lesson

[00:00:00]
>> So we've got most of it in place now, other than my bad level design. The only thing we'd have to solve for is double jumping. Easiest way to do that is just keep track of whether or not you're jumping, right? When you leave the ground, say you're jumping.

[00:00:15]
When you're back on the ground, say that you're not jumping. We could do that, yeah, I think we talked about other ways to do it before, but that was when we had a known ground. In this platform, again, we don't know the ground is always at negative 147.

[00:00:31]
We have no idea, right? So what we'd have to do is, say jumping. And when he leaves the ground, We just say that he's jumping.
>> Okay, so here.
>> So always set jumping to 0 at the beginning, cuz we know I've made that mistake enough times, same with x velocity.

[00:01:18]
And when he lands, we'll also set jumping to 0.
>> Change, this is a [INAUDIBLE].
>> We gotta make sure he can't jump when he is jumping. So we'll say, If-
>> And I wrote this y.
>> Jumping is 0, then let him jump, otherwise don't do anything.

[00:02:01]
Let's just make sure it works, he can't double jump anymore. His jump isn't high enough to get anywhere anymore. Again, my game is not good, but it works. Let's go down and see what we got. The easiest mistake that I would've made in this section is forgetting the ones where there might still be a change.

[00:02:27]
It's letting a y sneak into this x block will be the source of your bugs, or a common source of your bugs.

### Learn Straight from the Experts Who Shape the Modern Web

• In-depth Courses