Workshop › Endless Runner › Step 18 of 19

Duck

What we are doing

Holding the down arrow on the ground makes the runner shorter, low enough to pass under a bird. While ducking it cannot jump.

```js
const DUCK_H = 26

  // Duck only on the ground; keep the feet in place when the height changes.
  const h = keys.ArrowDown && onGround() ? DUCK_H : STAND_H
  runner.y += runner.h - h
  runner.h = h

  if (onGround() && runner.h === STAND_H) runner.vy = JUMP
```

What it means

Your turn

  1. Under STAND_H, write DUCK_H.
  2. In update, under the ground block, write the comment and the three duck lines.
  3. In jump, add && runner.h === STAND_H.

Skills: Keyboard and mouse input, Collision detection

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