Stage 2: Jump Controls
Stage 2: Jump Controls
Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.
gravity and a single jump button
how speed changes position every frame
a cube that jumps and lands on the floor
- Show ySpeed at 0 while the cube rests on the floor.
- Press space once and set ySpeed to 14.
- Run a forever loop that changes y by ySpeed, then changes ySpeed by gravity.
- 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.
- 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
Stage 1 should be done. Cube and the four variables should already exist.
Students may follow these examples or draw their own versions in Scratch. Keep the sprite names from the lesson.
Follow the target shapes shown here so your scripts match the lesson quickly.
Draw a custom cube, spikes, portal, or backdrop in Scratch. Keep the same sprite names so the code still works.
Build it
- Click the Cube sprite and open the Code tab.
- Keep yesterday's setup blocks at the top.
- Add the forever loop below under the setup blocks.
- Test with the space bar. The cube should jump once, fall, and stop on the floor.
- 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
Try this
Three short experiments. Predict before you run, then test your guess.
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.
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.