Game Dev From Zero · Episode 9

Jump lab

Gravity pulls a little every frame. A jump pushes a lot, once. Jump around, then change the numbers, and find out why a jump asks "was it pressed?" and not "is it held?".

The game ← → / A D move · Space / W / ↑ jump · R reset

Top row: jump is held (a state). Bottom row: jump was pressed (an event: one frame). Newest on the right.

velocity.y
0
on_ground
true
jump height
0 px
time in the air
0.00 s

The code lit = running now


    

The numbers

jump if the key…
on_ground check

"fall faster" multiplies gravity while you're falling. With these numbers a jump goes 48 px high, 0.80 s in the air.

Things to try

  1. Switch to is held and hold the jump key down. Boing, boing, boing…
  2. Turn the on_ground check off and mash jump. How high can you climb?
  3. Set fall faster to 2. Does the jump feel better or worse?
  4. Try Moon. Then make a jump that's just as high, but quick.
  5. Set gravity to 0 and jump. Bye! (Press R to bring the ghost back.)