Skip to content

aabbVsAabbSwept

aabbVsAabbSwept(a, motionA, b): SweptHit

Defined in: src/modules/collision/narrowphase.ts:111

Swept AABB: a moves by motionA toward static b. Returns the first fraction of motion at which they touch (tEntry ∈ [0, 1]) and the contact normal on b. Returns the shared frozen NO_HIT sentinel ({hit:false, tEntry:1, normal:{0,0}}) when there’s no collision this step.

The classic Minkowski-sum sweep: compute entry/exit times on each axis independently, then the actual entry is the latest entry and the actual exit is the earliest exit; they must overlap and fall within [0,1].

Edge cases (all return NO_HIT):

  • Already penetrating at t=0: callers that need depenetration should run aabbVsAabb separately before sweeping.
  • Zero motion on an axis where projections don’t overlap: no way to collide on that axis, so no collision at all.
  • Zero motion on an axis where projections overlap: that axis doesn’t constrain entry time; the other axis decides.
  • Both axes zero motion: always returns NO_HIT. Use aabbVsAabb for static overlap checks.

Corner-hit tie-break: when x.entry === y.entry, the y-axis normal wins (favouring vertical surfaces over horizontal edges).

Aabb

Vec2

Aabb

SweptHit