Scratch Platformer Game Series — Part 2: How to Make a Sprite Jump in Scratch
In Part 1 of our Garden Glitch Scratch Platformer series, we taught Byte how to move left and right across the greenhouse using the arrow keys. Now it is time to add one of the most important mechanics in almost every platform game: jumping.
Instead of programming Byte to simply move up and then move back down, we are going to build a simple gravity system. This creates a much smoother jump and gives us code that we can continue using when we add real platforms in the next part of the series.

In this Scratch coding activity, kids will work with y-coordinates, variables, positive and negative numbers, velocity, conditionals, and gravity while building a jump that actually feels like it belongs in a game.
By the end of Part 2, Byte will be able to run left and right, jump with the space bar, move horizontally while he is in the air, and land safely back on the greenhouse floor.

Play Garden Glitch Part 2
Try the finished project before building the jumping code yourself.
Use the left and right arrow keys to move Byte across the greenhouse. Press the space bar to jump.
Try moving left or right while Byte is already in the air. Notice that horizontal movement and vertical movement can happen at the same time.
Open Garden Glitch Part 2 on Scratch
You can click See Inside to explore the finished code before creating your own version.
What We’re Learning in Part 2
This lesson builds directly on the player movement system from Part 1.
Our two main concepts are: y-coordinate movement and simple gravity.
Along the way, we will also use a variable to represent vertical speed, positive and negative numbers to control direction, a conditional to keep Byte from falling through the floor, and a keyboard event to start each jump.
The important part is that we are still adding only one game system at a time.
We are not adding platforms yet. That comes in Part 3.
Start with the Part 1 Movement Code
Before beginning this lesson, Byte should already move left and right with the arrow keys.
The right arrow increases Byte’s x-coordinate:
change x by 5
The left arrow decreases it:
change x by -5
That controls horizontal movement. Now we need another system for vertical movement.
Understanding the Y-Axis in Scratch
Scratch uses two coordinates to determine where a sprite appears on the Stage.
The x-coordinate controls left and right movement. The y-coordinate controls up and down movement.
In our Garden Glitch project, Byte begins at:
x: -175
y: -50
The y: -50 position places Byte directly on the greenhouse walkway.
When Byte jumps, we will temporarily increase his y-coordinate so he moves upward. Gravity will eventually make his vertical movement negative and bring him back toward y: -50.
That means the same basic idea we used for left and right movement also works vertically.
Positive movement goes one direction. Negative movement goes the other.
Create a Variable for Vertical Velocity
Create a new variable named:
yVelocity
Choose For this sprite only.
This variable will store Byte’s current vertical speed.
When yVelocity is positive, Byte moves upward. When yVelocity is negative, Byte moves downward.
When it equals 0, Byte is not moving vertically.
This lets one number describe where Byte is in the entire jumping process.
Start Byte with No Vertical Movement
Under the green flag, initialize yVelocity:
when green flag clicked
set rotation style [left-right]
go to x: (-175) y: (-50)
set [yVelocity] to (0)
Byte begins on the ground, so his vertical speed should begin at zero.
We do not want the player sprite already moving upward or downward when the project starts.
This is an example of initializing a variable.
Before the game begins, we give important variables predictable starting values.

Move Byte Using the yVelocity Variable
Inside the main forever loop, underneath the left and right arrow controls, add:
change y by (yVelocity)
Instead of typing a fixed number into this Motion block, we use the value stored inside our variable.
If:
yVelocity = 12
Scratch changes Byte’s y-position by 12.
If:
yVelocity = -6
Scratch changes his y-position by negative six.
That means the same line of code can move Byte both upward and downward.
Add Gravity to the Jump
Immediately after:
change y by (yVelocity)
add:
change [yVelocity] by (-1)
This is our simple gravity system.
Every time the forever loop runs, Scratch subtracts one from Byte’s vertical velocity.
Imagine Byte begins a jump with:
yVelocity = 12
As the loop continues, the values become:
12
11
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
At first, Byte moves upward quickly.
As the number becomes smaller, he continues moving upward, but more slowly.
When yVelocity reaches 0, Byte reaches approximately the highest part of the jump.
Then the value becomes negative.
Now each loop moves Byte downward.
That creates the curved jumping motion you see in the finished project.
Why This Looks More Natural Than Moving Up and Down
We could build a much simpler jump like this:
change y by 50
wait 1 second
change y by -50
Technically, Byte would leave the ground and come back, but it would not behave much like a platformer jump.
The sprite would jump to one position, pause, and then drop.
Using velocity gives us gradual acceleration and deceleration.
Byte rises quickly, slows near the top, and accelerates downward again.
That small change makes the project feel much more like a real game.
Press Space to Jump
Now create a separate script:
when [space] key pressed
Under it, add:
if <(y position) = (-50)> then
set [yVelocity] to (12)
end

In plain language, the code says:
When the player presses Space, check whether Byte is standing on the greenhouse floor. If he is, give him an upward velocity of 12.
Setting yVelocity to 12 does not instantly move Byte to the top of the jump.
Instead, it gives our gravity system something to work with.
The main loop handles everything that happens afterward.
Why Check Byte’s Y-Position Before Jumping?
Without the condition:
y position = -50
the player could press Space repeatedly while Byte was already in the air.
Each press would reset:
yVelocity
back to 12.
Byte could essentially keep jumping upward forever.
Checking his position prevents that.
Byte can begin a new jump only while he is standing on the floor.
For this stage of our platformer, the floor is always at y: -50, so this simple check works well.
Later, when we add platforms at different heights, we will need a more flexible way to determine whether Byte is standing on a surface.
That is exactly what we’ll build in Part 3.
Keep Byte from Falling Through the Floor
Gravity never stops running.
That means if we do nothing, yVelocity will continue becoming more negative and Byte will fall straight through the greenhouse floor.
We need a temporary floor collision rule.
Under the gravity code, add:
if <(y position) < (-50)> then
set y to (-50)
set [yVelocity] to (0)
end
This checks whether Byte has moved below the greenhouse walkway.
If his y-coordinate drops below -50, Scratch immediately puts him back at:
y: -50
Then we reset:
yVelocity = 0
Byte is back on the ground and no longer moving downward.
Why We Use Less Than Instead of Equals
Notice that the condition is:
y position < -50
rather than:
y position = -50
Byte may move several Stage units during a single loop.
He might go from:
y: -47
to:
y: -54
without ever landing on exactly -50.
Checking whether the position is less than -50 catches anything below our floor.
Then we deliberately place Byte at the correct floor height.
This is a useful programming pattern: detect an invalid position → correct the position → reset the movement
We will use a more advanced version of this idea when we add platforms.
The Complete Part 2 Code
Byte’s main script should now look like this:
when green flag clicked
set rotation style [left-right]
go to x: (-175) y: (-50)
set [yVelocity] to (0)
forever
if <key [right arrow] pressed?> then
point in direction (90)
change x by (5)
end
if <key [left arrow] pressed?> then
point in direction (-90)
change x by (-5)
end
change y by (yVelocity)
change [yVelocity] by (-1)
if <(y position) < (-50)> then
set y to (-50)
set [yVelocity] to (0)
end
end
The jump script is:
when [space] key pressed
if <(y position) = (-50)> then
set [yVelocity] to (12)
end

It is still a relatively small program, but Byte can now move in two dimensions.
Horizontal and Vertical Movement Can Happen Together
One of the best parts of this system is that Byte can move left or right while jumping.
The x-axis code and y-axis code do not have to wait for each other.
While gravity changes Byte’s y-coordinate, the forever loop is still checking the left and right arrow keys.
That means you can press: Space + Right Arrow and Byte moves upward while also moving right.
Or: Space + Left Arrow
and he jumps toward the left. This is the beginning of real platformer movement.
Test Your Code
Click the green flag. Byte should appear on the greenhouse walkway.
First, test the Part 1 controls. Hold the right arrow and then the left arrow.
Next, press Space without touching any other key. Byte should rise, slow near the top, fall, and stop cleanly on the walkway.
Now press Space while holding the right arrow. Try again while holding the left arrow.
Finally, try pressing Space repeatedly while Byte is already airborne. He should not be able to jump again until he returns to the floor.
If all of those behaviors work, Part 2 is complete.
Debugging the Scratch Jump
Byte immediately jumps when I click the green flag
Check the initialization code.
It should say:
set yVelocity to 0
The value 12 should only appear in the Space-key jump script.
Byte falls through the greenhouse floor
Make sure this condition is inside your forever loop:
if y position < -50
The correction should set both:
y to -50
and:
yVelocity to 0
Byte keeps jumping higher when I press Space
Make sure your jump code checks:
y position = -50
before setting yVelocity to 12.
Byte jumps but never comes back down
Check:
change yVelocity by -1
The negative number is what creates gravity.
If you accidentally use positive 1, Byte will accelerate upward instead.
Experiment with Jump Height
Try changing:
set yVelocity to 12
to:
8
Test the game.
Then try:
16
Notice how much higher Byte travels.
This value acts like Byte’s initial jump strength.
The gravity value controls another part of the jump.
We currently use:
change yVelocity by -1
Try:
-2
Byte will lose upward velocity faster and fall more aggressively. Experimenting with these numbers is part of game tuning.
There is not always one mathematically perfect value. The goal is to find movement that feels good to play.
Remix Challenge: Design Byte’s Jump
Pick one jump-strength value and one gravity value.
Test several combinations.
For example:
Jump: 10
Gravity: -1
or:
Jump: 15
Gravity: -2
How does each combination change the feel of the game?
- Can you create a very floaty jump?
- Can you create a short, heavy jump?
- Which version feels most appropriate for Garden Glitch?

Why We Aren’t Adding Platforms Yet
Byte is now jumping over what looks like a platform, but our code doesn’t actually understand the greenhouse artwork.
Right now, the program only knows about one invisible rule:
The floor is at y = -50.
If we put a shelf halfway up the Stage, Byte would pass straight through it. The backdrop is just an image.
Scratch needs code that can detect where our actual game surfaces are. That gives us our next problem to solve.
What Comes Next in Garden Glitch?
In Part 3, we are going to build Scratch platform collision detection.
Instead of relying on a single fixed floor height, Byte will need to detect platforms and land on them.
That means we can finally begin turning our flat greenhouse scene into a real platforming environment.
We’ll use the jumping system from this lesson rather than rebuilding it.
Our development process remains: build → test → debug → expand
Next: Scratch Platform Collision Detection — Garden Glitch Part 3
You’ll Also Like
Garden Glitch Part 1: Move a Sprite with Arrow Keys

Start at the beginning of the series and build Byte’s horizontal movement using keyboard input, x-coordinates, conditionals, and sprite direction.
Scratch Chase Game: Make a Cat Chase a Mouse

Build a complete chase game while learning distance sensing, random movement, variables, broadcasts, and simple game AI.
Scratch Frog Game: Catch Flies Before Time Runs Out

Create a timed frog game with jumping, clones, sensing, variables, collision detection, and random movement.

Meet Toni, the Maker Mom behind Our Family Code
Hey there, I’m Toni! I’m a software engineer and Maker Mom that finds my joy in unleashing my children’s curiosity by exploring STEAM concepts with my fantastic five!
When I’m not chasing toddlers or raising tweens, you can find me tearing things up and putting them back together over here at Our Family Code.
I am the owner and content creator of multiple educational websites designed to increase access to STEAM & STEM education with a focus on teaching computer science and coding to kids of all ages!













