Workshop › Pong › Step 15 of 26
A ball moving left that touches the left paddle turns around, and is placed just outside the paddle so it does not touch it again next frame. The same on the right.
```js
if (ball.vx < 0 && touches(left)) {
ball.vx = -ball.vx
ball.x = left.x + PADDLE_W
}
if (ball.vx > 0 && touches(right)) {
ball.vx = -ball.vx
ball.x = right.x - BALL
}
```ball.vx < 0 means moving left; together with touches(left), the left paddle hits it.ball.vx = -ball.vx turns it around.left.x + PADDLE_W is the left paddle's right edge: the ball is put right next to it. For the right paddle, just
before its left edge.At the end of update, under the wall bounce block, write the two paddle blocks.
Skills: Collision detection, Velocity and gravity
← Does the ball touch a paddle? Serve again →