🏆 Phase 4 · Advanced Projects
🟣 Advanced
MODULE 13
Platform Jumper
Your progress in Phase 425%
🎯 What you'll learn: How to simulate gravity in Scratch using a variable, making a character feel realistic as it falls and jumps. This is the most important technique in platform games like Mario!
Section 1
Simulating Gravity with a Variable
Real gravity pulls things down faster and faster — it accelerates. In Scratch, we fake this with a velocity variable. Every frame, velocity gets a little more negative (pulling down), and the sprite's Y position changes by that velocity.
GRAVITY IN ACTION — THE VELOCITY BUILDS UP EACH FRAME
🐱
Frame 1
vel: -1
🐱
Frame 2
vel: -2
🐱
Frame 3
vel: -3
🐱
Frame 4
vel: -4
🐱
Frame 5
vel: -5
Each frame, velocity increases downward — the cat falls faster and faster!
🐱
⭐
FLOOR (colour detect)
Platform (same colour)
GOAL — reach it!
Platform 2
🦘
Jumper
velocity_y remembers how fast you're falling or jumping
when 🚩 clicked
set velocity_y to 0
go to x: -180 y: -130
forever
change velocity_y by -1
change y by velocity_y
if touching color 🟩 ? then
set velocity_y to 0
change y by 2
if key space pressed? then
if touching color 🟩 ? then
set velocity_y to 12
if key right arrow pressed? then
change x by 4
if key left arrow pressed? then
change x by -4
💬 In kid words: "Every moment, gravity pulls you down a little more (velocity_y gets smaller). Standing on green ground? Falling stops. Press space while on the ground? velocity_y becomes 12 and WHOOSH — you launch into the air, then gravity slowly brings you back down!"
Section 2
Build: Platform Jumper Step by Step
1
Design the level backdrop
Draw a platform level on the Stage backdrop. Floor at the bottom in green. Add 3-5 floating platforms (also green). Add a star or flag at the top-right as the goal!
2
Create the velocity variable
Create a variable called
velocity_y. This stores how fast the player is moving up or down. Uncheck "Show variable" — players don't need to see it!3
Set up the player sprite
Use a small cat or custom sprite. Set size to 40%. Place it near the bottom-left. The player must jump up the platforms to reach the goal!
4
Code the gravity loop
Add the gravity code from Section 1. Test it — the cat should fall, land on platforms, and be able to jump with Space!
5
Add the win condition
Use a separate "star" sprite as the goal. In the player's code: if touching [Star] then say "You Win! 🌟" → stop all. Or use colour detection for the goal zone!
6
Add lives and obstacles
If player falls below y:-170 → change lives by -1 → go back to start. Add a moving enemy sprite that the player must avoid!
🎮
Make the jump feel right!
The feel of a jump matters a lot! If
velocity_y starts at 12 and gravity is -1, the jump arc lasts about 24 frames. Try: velocity = 10, gravity = -0.8 for a floatier jump. Velocity = 15, gravity = -1.5 for a snappier jump. Experiment!🧩 Knowledge Check — Lesson 13
5 questions on platform game physics!
1. In Scratch gravity simulation, what does the "velocity_y" variable represent?
2. To simulate gravity, what happens to velocity_y every frame?
3. When the player jumps, what value should velocity_y be set to?
4. Why should we only allow jumping when the player is touching the ground colour?
5. What should happen to velocity_y when the player lands on a platform?