two collision passes, two answers
alreadyYou know the ball moves in fixed slices and that state.ts holds its position.
hereWhy paddle and wall collisions are resolved in separate x and y passes, and what a corner would do with one pass.
Page: two collision passes, two answers
Job: explanation
Level: mid grug (level 2 of 6)
Source lines:
why grug give these 3 tool notes
why grug give the proof why grug give the grill why grug give the why under an answerthis page says why the code has this shape and what a reader must be careful of.
This page teaches why the ball's x and y corrections run as two separate passes, so a corner hit resolves in a fixed order instead of a coin toss.
why
The ball moves in x and y as two separate actions. The paddle pass at update.ts:62#hface runs after the x move, checks overlap with overlaps at state.ts:59#overlaps, reverses vx and pushes the ball clear in x. The wall pass at update.ts:73#vface runs after the y move and corrects y alone.
Order matters here. A corner hit can overlap a paddle and a wall in one step, and each pass has one correction to make. Separating them gives a deterministic answer for that corner, and the ball leaves the step outside both surfaces. The note at docs/003-axis-separated-collision.md:3#accepted records this choice.
In the picture, the three panels are one step read left to right: both overlaps real at once, the paddle pass touching only x and vx, the wall pass touching only y and vy, and the ball clear of both surfaces at the end. Neither pass looks at the other axis, which is what makes the pair readable as two claims.
what breaks
A single combined rectangle test would have to choose which overlap to fix first. The other overlap would survive into the next step, and the ball could be pushed back into the paddle or through the floor. A reader would then chase a bug that only shows at the corners.
Skipping the push-out leaves the ball inside the paddle at the start of the next step. The guard sees the reversed velocity and lets the ball travel out; a corner hit can spend another step still overlapped.
where it fits
step calls the two passes in a fixed order, then asks score_if_out about the goal line. The decision is written in docs/003-axis-separated-collision.md and its built page docs/003-axis-separated-collision.html.
try it
Move the left paddle into the top corner and send the ball there. The ball should leave on the x correction, then meet the wall correction on the next y move. The proof prints both passes; the decisive line is update.ts:62#hface.
run grep -n -E 'hface|vface' update.ts
It prints:
62:export function resolve_paddle_hits(game: Game): void { // hface: paddle contact corrects x only
73:export function resolve_wall_hits(game: Game): void { // vface: wall contact corrects y only
The cited file update.ts ships with this site at the same path. Run the command from the school folder, or open update.ts.
Run the source check from the repository root:
grep -n 'export function resolve_paddle_hits' update.ts
The source check for this page names the paddle pass:
run grep -n 'export function resolve_paddle_hits' update.ts
It prints:
62:export function resolve_paddle_hits(game: Game): void { // hface: paddle contact corrects x only
The cited file update.ts ships with this site at the same path. Run the command from the school folder, or open update.ts.
reference: the guards around each pass
The paddle pass fires only on approach: game.ball.vx < 0 for the left paddle, game.ball.vx > 0 for the right. A ball moving away from a paddle it already bounced off does not get its velocity flipped again, which is why the pushed-out ball can travel out of the overlap on its own.
The wall pass checks both edges unconditionally, top at game.ball.y - BALL_RADIUS < 0 and bottom at game.ball.y + BALL_RADIUS > WINDOW_H. Each test clamps the coordinate to the surface and flips vy, so the ball spends no second step inside a wall.
reference: every connection to this page
This is reference. The next page in the reading order is at the bottom of the page.
learn first: time arrives in equal slices
goes on to: a goal changes one score, then waits, why collision keeps two passes, change one rule, follow the result
flowchart LR A0["time arrives in equal slices"] H["you are here: two collision passes, two answers"] B0["a goal changes one score, then waits"] B1["why collision keeps two passes"] B2["change one rule, follow the result"] A0 --> H H --> B0 H --> B1 H --> B2
this badge records quiz answers with a difficulty from 1 to 6. it does not measure independence or responsibility.
grill: check what you know
Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.
the number is a question's difficulty from 1 to 6. a coloured chip marks a question that asks for a change, an effect or a judgment, declared in the quiz row. the rung badge records quiz answers: two right at a level and the levels below it, with a declared transfer question at level 5 or 6. it does not certify independence or responsibility. the questions are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer.
try first, then show answer
3. vx alone
The paddle pass at update.ts:62#hface reverses vx and leaves vy alone. It runs after the horizontal move.
try first, then show answer
2. To clear the overlap after the bounce
A hit sets the ball x to the paddle edge at update.ts:65#pushout. The push clears the overlap so the ball starts the next step outside the paddle. Scores change only at the goal line.
try first, then show answer
1. y alone
The wall pass at update.ts:73#vface clamps y and reverses vy. It runs after the vertical move and leaves x alone.
try first, then show answer
3. The call order of the two passes
step moves in x at update.ts:36#xpass, then resolves paddles, then moves in y at update.ts:38#ypass, then resolves walls. Call order decides a corner hit; draw order and scores take no part.
try first, then show answer
3. To keep a ball already leaving the paddle from being flipped back into it
The paddle tests inside resolve_paddle_hits at update.ts:62#hface require vx moving toward the paddle before the flip. A ball the pass already pushed out and reversed would fail the guard on the next step, so the bounce cannot flip the velocity a second time.
try first, then show answer
3. Its x was already corrected by the paddle pass; the wall pass corrects y alone
resolve_wall_hits at update.ts:73#vface writes only y and vy. The x overlap was the paddle pass's question, and its correction already ran; the wall pass leaves x exactly as it found it.
try first, then show answer
resolve_wall_hits
step fixes paddles at update.ts:62#hface and walls at update.ts:73#vface in that order. A combined test that returns on the paddle hit skips the wall clamp and the vy flip, so that overlap waits for the next step. The ADR records the surviving overlap at docs/003-axis-separated-collision.md:11#winner.