Workshop › Doodle Jump-style Climber › Step 3 of 24

Gravity

What we are doing

The player gets a vertical speed vy. Every frame gravity adds to it and the speed moves the player, so it falls faster and faster, until its feet reach the floor.

```js
const GRAVITY = 0.35
const FLOOR = 600 // the bottom of the canvas

let player = { x: 180, y: 460, w: 40, h: 40, vy: 0 }

function update() {
  player.vy += GRAVITY
  player.y += player.vy
  if (player.y + player.h >= FLOOR) {
    player.y = FLOOR - player.h
    player.vy = 0
  }
}

  update()
```

What it means

Your turn

  1. Under ctx, write GRAVITY and FLOOR; add , vy: 0 to player.
  2. Under player, write update; call it in loop before draw().

Skills: Velocity and gravity

All steps

  1. The jumper
  2. Draw again and again
  3. Gravity
  4. Bounce
  5. Steer left and right
  6. Through the sides
  7. Half here, half there
  8. Touch steering
  9. Platforms
  10. Land on platforms
  11. A camera that follows
  12. Lines on the wall
  13. How hard should it be?
  14. Endless platforms
  15. Miss and fall
  16. Play again
  17. Tap to play again
  18. Score is height
  19. Best score
  20. Kinds of platform
  21. Moving platforms
  22. Traps
  23. It breaks!
  24. Build it yourself: springs