Workshop › Endless Runner › Step 6 of 19

Short hops

What we are doing

Good platform games let you control the jump: hold the key for a high jump, tap it for a short hop. When the key is let go while still rising fast, the upward speed is cut to -4.

```js
const CUT = -4 // letting go early caps the upward speed at this

// Letting go early makes a short hop: cap the upward speed.
function endJump() {
  if (runner.vy < CUT) runner.vy = CUT
}

document.addEventListener('keyup', (event) => {
  if (event.key === ' ' || event.key === 'ArrowUp') endJump()
})
```

What it means

Your turn

  1. Under JUMP, write CUT.
  2. Under jump, write the comment and endJump.
  3. Under the keydown listener, write the keyup listener.

Skills: Velocity and gravity, Keyboard and mouse input

All steps

  1. The ground
  2. The runner
  3. Draw again and again
  4. Gravity
  5. Jump
  6. Short hops
  7. Tap to jump
  8. Things that come at you
  9. Cacti keep coming
  10. Wait for the start
  11. Crash
  12. Try again
  13. Faster and faster
  14. Remember the best run
  15. The score counter
  16. Birds
  17. Which keys are down?
  18. Duck
  19. Build it yourself: jump buffering