The size of the kick that resolves a contact comes from one formula involving restitution and inverse mass. Today you compute the impulse scalar, the core of collision response.
Compute the impulse magnitude for a contact from the relative normal velocity, restitution, and inverse masses.
The impulse magnitude j is the strength of the instantaneous change in momentum
that resolves a contact. Its formula, j = -(1 + e) * vn / (imA + imB), packs three
ideas: the closing speed vn sets the scale, the restitution e decides how much
of it bounces back (0 for a dead stop, 1 for a perfect rebound, so 1 + e ranges
from 1 to 2), and dividing by the total inverse mass shares the kick between the two
bodies by how movable each is. A lighter body takes more of the velocity change.
The negative sign turns the negative closing velocity into a positive push apart. Guard
the separating case: if vn is already positive the bodies are parting on their own, so
j is 0 - no impulse, matching the resting-contact rule from last lesson. For two
equal-mass bodies closing at -2, a perfect bounce gives j = 2 and a dead one gives
j = 1. Next lesson turns this magnitude into an actual velocity change.
// j = -(1 + e) * vn / (invMassA + invMassB), and never negativefunc ImpulseMagnitude(vn, e, imA, imB float64) float64 {if vn > 0 { return 0 } // already separating: no impulsereturn -(1 + e) * vn / (imA + imB)}