Skip to main content

Stage 2: Jump Controls

Stage 2: Jump Controls

Course progressStage 2 of 10
~60 min
Your workspace

Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.

Build

gravity and a single jump button

Learn

how speed changes position every frame

Ship

a cube that jumps and lands on the floor

Teacher demo
  1. Show ySpeed at 0 while the cube rests on the floor.
  2. Press space once and set ySpeed to 14.
  3. Run a forever loop that changes y by ySpeed, then changes ySpeed by gravity.
  4. Clamp the cube back to the floor when it falls below y: -90.

The big idea

Jumping is not teleporting. A jump starts by pushing the cube upward, then gravity pulls that speed down until the cube lands.

New words
gravity
the downward pull that changes ySpeed every frame
ySpeed
how fast the cube is moving up or down
floor
the lowest safe y position for the cube
clamp
forcing a value back inside a safe limit
Before you start

Stage 1 should be done. Cube and the four variables should already exist.

Use the examples

Follow the target shapes shown here so your scripts match the lesson quickly.

Make your own

Draw a custom cube, spikes, portal, or backdrop in Scratch. Keep the same sprite names so the code still works.

Build it

  1. Click the Cube sprite and open the Code tab.
  2. Keep yesterday's setup blocks at the top.
  3. Add the forever loop below under the setup blocks.
  4. Test with the space bar. The cube should jump once, fall, and stop on the floor.
  5. Save when the jump feels consistent.

Cube jump loop

forever
if <(gameOn) = (1)> then
if <<key [space v] pressed?> and <(y position) = (-90)>> then
set [ySpeed v] to (14)
end
change y by (ySpeed)
change [ySpeed v] by (gravity)
if <(y position) < (-90)> then
go to x: (-150) y: (-90)
set [ySpeed v] to (0)
end
end
end

Understand it

The cube only jumps from the floor. That prevents double-jumping, which would make the spike timing too easy for this version.

Try this

Learning beat

Try this

Three short experiments. Predict before you run, then test your guess.

Predict first
Change ySpeed from 14 to 6 before jumping. Predict how the jump changes.
Compare
Try gravity -1, then -2. Which one feels more like a rhythm game?
Connect
Stage 3 adds spikes. Why is a reliable floor position important before collision code?

Test your stage

  • Space makes the cube jump.
  • The cube falls back down instead of floating.
  • The cube stops at y: -90.
  • Holding space does not fly forever.

If it breaks

  • If the cube sinks, check the floor if-block and y value.
  • If the cube never jumps, check that gameOn is 1 and the key dropdown says space.
Coach notes

Keep students moving on the default path first. Custom assets are encouraged, but the required names and variables are not optional. If debugging takes more than a few minutes, compare the student's sprite names, variable names, and block order against the stage test list.