Workshop › Pool › Step 31 of 33
The hit ball leaves along the line from the ghost ball's centre through its own centre: that is the normal of the collision. We draw that line too, so you can aim a ball into a pocket.
```js
// The ball that is hit goes off along the line from the ghost ball through its centre.
const dx = g.ball.x - g.x
const dy = g.ball.y - g.y
ctx.beginPath()
ctx.moveTo(g.ball.x, g.ball.y)
ctx.lineTo(g.ball.x + dx * 3, g.ball.y + dy * 3)
ctx.stroke()
```(dx, dy) goes from the ghost ball's centre to the hit ball's centre: 2R long, pointing where it will go.In the if (g) block, under the ghost ball's ctx.stroke(), write the comment and the six lines.
Skills: Velocity and gravity, Drawing on a canvas
← Draw the ghost ball Your best →