Workshop › Pool › Step 9 of 33

A shot is a velocity

What we are doing

A shot gives the cue ball a velocity: a speed, power, in the direction aim. The same cos and sin split it into the two parts the position needs, vx and vy. Space shoots.

```js
let power

  power = 8

function shoot() {
  cue.vx = Math.cos(aim) * power
  cue.vy = Math.sin(aim) * power
}

  else if (event.key === ' ') shoot()
```

What it means

Your turn

  1. Under let aim ... write let power; in reset, under aim = 0, write power = 8.
  2. Under reset, leave an empty line and write shoot.
  3. In the key listener, add the Space line above else return.

Skills: Velocity and gravity

All steps

  1. The room
  2. The table
  3. The cue ball
  4. Draw the balls
  5. The rack
  6. Numbers on the balls
  7. An aim line
  8. Turn the aim
  9. A shot is a velocity
  10. Roll
  11. Friction
  12. Cushions
  13. Aiming and rolling
  14. Hide the aim while rolling
  15. Count the shots
  16. Balls that touch
  17. Swap the push
  18. Six pockets
  19. In the pocket
  20. Scratch
  21. Balls left
  22. Clear the table
  23. Choose the power
  24. A power bar
  25. A slingshot
  26. Press to aim
  27. Pull back and let go
  28. Smaller steps
  29. Predict the hit
  30. Draw the ghost ball
  31. Where the hit ball goes
  32. Your best
  33. Build it yourself: two players