Workshop › Pinball › Step 18 of 42
A wall gives back part of the speed; a bumper adds energy. We cancel the ball's speed into the bumper and give it a fixed kick of 6 outwards, so even a slow ball flies away.
```js
// A bumper kicks the ball away, faster than it came.
const vn = ball.vx * nx + ball.vy * ny
ball.vx += (-vn + 6) * nx
ball.vy += (-vn + 6) * ny
```vn is the speed along the normal (negative: towards the bumper).-vn along the normal cancels it; adding 6 more sends the ball away at exactly 6, whatever it came in at.In hitBumper, at the end, under ball.y = b.y + ..., write the comment and the three lines.
Skills: Velocity and gravity
← The ball meets a bumper A score and a fresh start →