Game Rig

Home/Blog/Reflection

Breakout's reflection bug

The clamp in the copied paddle bounce does bite, but it bites at the ball's radius, not at the paddle's edge.

The paddle bounce in Brick Buster ends in two lines. The first computes how far off centre the contact was, divided by half the paddle's width, and pushes the result through a clamp to keep it between -1 and 1. The second multiplies that by 1.02 and turns it back into a velocity. With a 148 pixel paddle the divisor is 74, and 1.02 radians is 58.44 degrees away from vertical.

That clamp is not decoration. The test above it is a box overlap, so the ball counts as caught while any part of it is still touching the paddle. Its centre can therefore travel a full 8 pixels past either end before the test stops firing, and the raw ratio would reach 1.108 rather than 1. The clamp is what holds the exit angle at the 58 degrees the rest of the tuning assumes.

The story that circulates with this snippet is that the clamp throws away the outer part of the paddle — that some strip of it is dead to the player. Working the arithmetic through on the numbers above puts it the other way round. The paddle's edge is fine. It is the region past the edge that gets flattened.

The clamp's flat band starts outside the paddle

Put the ball's centre at seven positions along the paddle and read what the clamp returns at each. The third column is what the divisor of 74 produces; the fourth is what the player sees.

Reading the clamp at a 148 pixel paddle with a 74 pixel half-width
Ball centre, offset from the paddle's middleRatio before the clampRatio afterExit angle from vertical
82 px, 8 px past the left edge-1.108-1.000-58.4 degrees
74 px, exactly the left edge-1.000-1.000-58.4 degrees
37 px, halfway out-0.500-0.500-29.2 degrees
0 px, dead centre0.0000.0000 degrees
74 px, exactly the right edge1.0001.00058.4 degrees
82 px, 8 px past the right edge1.1081.00058.4 degrees

Two rows carry the point. At 74 pixels off centre the ball is on the paddle's edge, the ratio is exactly 1.000, and the exit angle is the full 58.4 degrees that the paddle is supposed to be able to produce. Nothing has been taken from the paddle there. At 82 pixels the centre is a radius past the edge, the ratio asks for 1.108, and the clamp answers 1.000, so the contact leaves at the same angle as one eight pixels further in.

Counted honestly, the clamp costs 6.3 degrees at each end and it costs them outside the paddle. As a share of the paddle's own width the band is 16 pixels out of 148, which is 10.8 per cent — close enough to an eighth to explain where the number in the summary came from, and the wrong denominator all the same. The eighth in question is a slice of the range the hit test allows, and that range sits past the edge.

A narrow paddle pays more for the same clamp

The overhang is set by the ball's radius while the paddle width is not, so the flat band grows as a share of the paddle as the paddle shrinks. Brick Buster carries three paddle widths, and the red triangle roof-tile hands out the narrow one for ten seconds at a time.

The same 8 pixel overhang measured against three paddle widths, all capped at 58.4 degrees
Paddle widthLargest ratio the hit test allowsAngle the clamp removesFlat band as a share of the paddle
82 px, the narrow paddle1.19511.4 degrees19.5 per cent
148 px, the base paddle1.1086.3 degrees10.8 per cent
214 px, the wide paddle1.0754.4 degrees7.5 per cent

On the wide paddle the clamp removes 4.4 degrees of angle and 7.5 per cent of the width. On the narrow one it removes 11.4 degrees and 19.5 per cent, so very nearly a fifth of the paddle's face sits in a band that can only produce one angle. The paddle that is hardest to aim with is the one whose aim range has been clipped hardest, which follows from the arithmetic rather than from any decision anyone made about powerups.

A second effect pushes the same way. The ball advances in sub-steps of at most six pixels and the paddle test runs after each one, so a fast ball is usually caught with its centre a few pixels nearer the edge than the ideal contact point. A generous hit test and a coarse sub-step both put the centre outside the paddle more often than the geometry alone suggests. The test itself is the ordinary box overlap covered in the piece on picking a hitbox, and it is not the part I would change.

The 1976 machine had no paddle formula to copy

None of this arithmetic came from 1976, because the 1976 machine had none to give. Breakout is discrete logic with no processor in it at all; Wozniak's prototype came in at 42 chips and the version Atari could actually manufacture used roughly a hundred TTL chips instead. What the original varied over a rally was speed, not angle: the ball gets faster after four hits, faster again after twelve, and the paddle halves in width once the ball reaches the top wall behind the red row.

The paddle behaviour it inherited came from Pong. Alcorn split that paddle into eight segments, the segment the ball struck picked the outgoing direction outright, and there was neither a continuous function nor any use for the approach angle. Segment eight and segment one were not two ends of a scale; they were two of eight answers.

So the modern snippet is a later invention wearing an old game's clothes. What survived from 1976 is the idea that the contact point decides the exit and the incoming direction is discarded. The continuous ratio, the clamp and the maximum angle are all things a tutorial added, which means the clamp cannot have been copied from the hardware. It has to be justified on what it does to the angles.

Two ways to spend the flattened angle

The first option keeps the clamp and repairs the divisor. Divide by the whole reachable half-range instead of by half the paddle — 82 rather than 74 — and the mapping becomes linear across every position the hit test can produce, with no flat band anywhere. The paddle's edge then yields 52.7 degrees instead of 58.4, and the angle at that edge now depends on the ball's radius, because the radius is inside the divisor. That coupling is the price: change the ball's size for a visual reason and the aiming changes with it.

The second option keeps the divisor and tightens the test, so the ball's centre has to be inside the paddle's span before the hit registers. The clamp can then never fire and can be deleted, and the ratio means exactly what its comment says it means. The cost lands at the corners: a ball clipping the outer eight pixels of a moving paddle with its centre outside goes straight through, and a player watching that happen does not conclude that the arithmetic is tidy. A paddle that let the ball past is the worse complaint.

Brick Buster keeps both and pays the 6.3 degrees. The flat band is outside the paddle and the cap is where the tuning wanted a cap anyway. Given the choice again I would rewrite the comment rather than the line, to say the clamp is there for the ball's radius, not the paddle.

Pros and cons

Pros

  • A generous box hit test never misses a corner contact, so the ball cannot appear to pass through a paddle the player saw it touch.
  • The exit angle stays capped at 58.4 degrees, which keeps the ball out of the near-horizontal shuttle that stalls a level.
  • The ratio depends only on the paddle's half-width, so a powerup that resizes the paddle needs no knowledge of the ball.
  • The clamp is three characters and it makes the worst case bounded, which matters in code that gets rewritten at midnight.

Cons

  • Every contact from 74 to 82 pixels off centre leaves at the same angle, so the flattest shot available is 6.3 degrees less flat than the formula can express.
  • The cost scales the wrong way: the clamp takes 19.5 per cent of the narrow paddle's width and only 7.5 per cent of the wide one.
  • A clamp is a symptom being treated. The flat band exists because the hit test lets the centre out of the paddle, and clamping the angle hides that rather than fixing it.
  • The angle at the extreme depends on the ball's radius through the overhang, so a change made for looks moves the aim.

Sources

  • Breakout (video game) — the 1976 cabinet's discrete logic, the 42 chip prototype against the hundred chip production board, and the four and twelve hit thresholds the ball's speed is keyed to.
  • Research Paddle Bounce — the survey of how paddle games pick an outgoing direction, including Alcorn's eight Pong segments and the note that the incoming angle is discarded rather than reflected.
  • Building a Breakout game in the browser — a worked version of the same centre-relative ratio at a 60 degree cap, with the argument for that range and no clamp at all, which is what made me check what mine was doing.