Workshop › Breakout › Step 10 of 39
The top wall works the same way, with one safer trick: instead of flipping vy, we force it to point down with
Math.abs.
```js
if (ball.y - BALL_R < 0) {
ball.vy = Math.abs(ball.vy)
ball.y = BALL_R
}
```ball.y - BALL_R < 0 is true when the top edge is above the canvas.Math.abs drops the minus sign: Math.abs(-4) is 4, which always means "down".ball.y = BALL_R puts the ball just below the ceiling.Write the new if right under the closing } of the side-wall if.
Skills: Collision detection, Velocity and gravity
← Bounce off the side walls The open floor →