Workshop › Breakout › Step 13 of 39
Where the ball lands on the paddle should decide its angle: the middle sends it straight up, the ends send it off to the side. That gives the player control.
```js
// -1 at the paddle's left end, 0 in the middle, 1 at the right end
const offset = (ball.x - (paddle.x + PADDLE_W / 2)) / (PADDLE_W / 2)
ball.vx = offset * 5
```paddle.x + PADDLE_W / 2 is the paddle's middle; ball.x minus it is how far right (+) or left (-) the ball is.* 5: the sideways speed is at most 5 pixels per frame.Write the three lines at the top of the if (onPaddle) { block, above ball.vy = ....
Skills: Velocity and gravity
← Bounce off the paddle A row of bricks →