Impulses and Restitution
Collision detection answers "are these two shapes touching, where, and along which normal?" Collision response decides what happens next. Real objects push on each other with a huge force for a tiny moment. A game engine can't integrate a force that lasts a microsecond, so it skips the force and changes the velocities directly. That instant change of momentum is an impulse:
impulse J = force × duration = change in momentum = m · ΔvAlmost every rigid-body engine (PhysX, Box2D, Jolt, Rapier, Chaos) resolves contacts with impulses. This lesson derives the impulse for one contact, first without rotation and then with it.
The contact equation
Two bodies A and B touch at a contact point with a normal n that points from A to B (the SAT and GJK lessons produce it). Their relative velocity along the normal is
vn = dot(vB - vA, n)vn < 0: they are moving toward each other, so the contact needs an impulse.vn >= 0: they are already separating, so leave them alone. Skipping this check makes resting objects stick together.
The coefficient of restitution e (0 to 1) says how much of the approach speed comes back: after the impulse we want vn' = -e · vn. With e = 0 the objects stop dead along the normal (clay), and with e = 1 they bounce with no loss (an ideal superball).
Apply an impulse of size j along n, pushing A backward and B forward:
vA' = vA - (j / mA) n vB' = vB + (j / mB) nPut that into vn' = -e · vn and solve for j:
j = -(1 + e) · vn / (1/mA + 1/mB)Engines store inverse mass (invMass = 1/m) instead of mass. A static or kinematic body gets invMass = 0: it has "infinite mass", the formula still works, and its velocity never changes. No special case is needed for walls and floors.
#include <iostream>
#include <iomanip>
#include <cmath>
struct Body { double invMass, v; }; // 1D: velocity along the contact normal (+x)
double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
// Resolve one contact with the normal pointing from a to b.
void resolve(Body& a, Body& b, double e) {
double vn = b.v - a.v; // relative velocity along n
if (vn >= 0) return; // separating: no impulse
double j = -(1 + e) * vn / (a.invMass + b.invMass);
a.v -= j * a.invMass;
b.v += j * b.invMass;
}
int main() {
std::cout << std::fixed << std::setprecision(3);
std::cout << " e | vA' vB' | momentum | kinetic energy\n";
for (double e : {0.0, 0.5, 0.8, 1.0}) {
Body a{1.0 / 2, 3}, b{1.0 / 1, -1}; // A: 2 kg at +3 m/s, B: 1 kg at -1 m/s
resolve(a, b, e);
double p = 2 * a.v + 1 * b.v;
double ke = 0.5 * 2 * a.v * a.v + 0.5 * 1 * b.v * b.v;
std::cout << std::setw(5) << e << " | " << std::setw(6) << z0(a.v) << " " << std::setw(6) << z0(b.v)
<< " | " << p << " | " << ke << "\n";
}
std::cout << "before: momentum 5.000, kinetic energy 9.500\n";
} e | vA' vB' | momentum | kinetic energy
0.000 | 1.667 1.667 | 5.000 | 4.167
0.500 | 1.000 3.000 | 5.000 | 5.500
0.800 | 0.600 3.800 | 5.000 | 7.580
1.000 | 0.333 4.333 | 5.000 | 9.500
before: momentum 5.000, kinetic energy 9.500
Momentum is the same in every row: an impulse pushes equally hard on both bodies in opposite directions (Newton's third law), so it can only move momentum between them. Kinetic energy is what restitution controls. At e = 1 it survives completely, and at e = 0 the bodies end with the same velocity and the "lost" energy is gone (in reality it becomes heat, sound and deformation).
Mass ratios and static bodies
The denominator 1/mA + 1/mB decides who gets pushed. A ping-pong ball hitting a bowling ball barely moves the bowling ball. In the limit, a wall with invMass = 0 doesn't move at all and the ball simply reflects its normal velocity, scaled by e.
#include <iostream>
#include <iomanip>
#include <cmath>
struct Body { double invMass, v; };
double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
void resolve(Body& a, Body& b, double e) {
double vn = b.v - a.v;
if (vn >= 0) return;
double j = -(1 + e) * vn / (a.invMass + b.invMass);
a.v -= j * a.invMass;
b.v += j * b.invMass;
}
int main() {
std::cout << std::fixed << std::setprecision(3);
// A 1 kg ball at 4 m/s hits a resting body of increasing mass (e = 0.5).
std::cout << " mass B | ball after | B after\n";
for (double mB : {1.0, 10.0, 100.0, 1000.0}) {
Body ball{1.0, 4}, other{1.0 / mB, 0};
resolve(ball, other, 0.5);
std::cout << std::setw(8) << mB << " | " << std::setw(10) << z0(ball.v) << " | " << z0(other.v) << "\n";
}
Body ball{1.0, 4}, wall{0.0, 0}; // static: inverse mass 0
resolve(ball, wall, 0.5);
std::cout << " static | " << std::setw(10) << z0(ball.v) << " | " << z0(wall.v) << "\n";
} mass B | ball after | B after
1.000 | 1.000 | 3.000
10.000 | -1.455 | 0.545
100.000 | -1.941 | 0.059
1000.000 | -1.994 | 0.006
static | -2.000 | 0.000
The result approaches the static case smoothly, so a very heavy body behaves like a wall. That smoothness is what you want from the math. The solver is another matter: when many contacts are solved one after another, large mass ratios converge badly (a heavy box on a light box sinks and jitters). The stacking lesson and the field notes explain why engines advise keeping mass ratios under about 10:1.
Adding rotation
A box hit at a corner spins. The contact point is at offset rA from A's center of mass (and rB from B's), and the velocity of that point includes the spin: in 2D, v + ω × r = v + ω · (-r.y, r.x). The impulse also produces an angular impulse r × J, which changes ω by I⁻¹ (r × J). Solving the same equation gives one extra term per body in the denominator:
j = -(1 + e) · vn / (1/mA + 1/mB + (rA × n)² / IA + (rB × n)² / IB)rA × n is the 2D cross product (a scalar, see Cross Product). It measures how far "off-center" the hit is. A hit through the center of mass has r × n = 0, the extra term vanishes and the body doesn't spin. The Rotation, Torque and Inertia lesson covers I and ω.
#include <iostream>
#include <iomanip>
#include <cmath>
struct Vec2 { double x, y; };
Vec2 operator+(Vec2 a, Vec2 b) { return {a.x + b.x, a.y + b.y}; }
Vec2 operator-(Vec2 a, Vec2 b) { return {a.x - b.x, a.y - b.y}; }
Vec2 operator*(Vec2 v, double s) { return {v.x * s, v.y * s}; }
double dot(Vec2 a, Vec2 b) { return a.x * b.x + a.y * b.y; }
double cross(Vec2 a, Vec2 b) { return a.x * b.y - a.y * b.x; }
Vec2 cross(double w, Vec2 r) { return {-w * r.y, w * r.x}; } // ω × r in 2D
double z0(double v) { return std::fabs(v) < 5e-4 ? 0.0 : v; }
struct Body { Vec2 pos, vel; double w, invMass, invI; };
// A falling box (1 x 1 m, 1 kg) lands on static ground; contact at offset `hitX` from its center.
void land(double hitX) {
double I = 1.0 * (1 * 1 + 1 * 1) / 12; // box inertia m(w²+h²)/12
Body box{{0, 0.5}, {0, -2}, 0, 1.0, 1 / I};
Vec2 contact{hitX, 0}, n{0, 1}; // normal from ground (A) up to box (B)
double e = 0.2;
Vec2 r = contact - box.pos;
Vec2 vPoint = box.vel + cross(box.w, r);
double vn = dot(vPoint, n); // ground is still, so vRel = vPoint
double rn = cross(r, n);
double j = -(1 + e) * vn / (box.invMass + rn * rn * box.invI);
box.vel = box.vel + n * (j * box.invMass);
box.w += cross(r, n * j) * box.invI;
std::cout << "hit at x = " << std::setw(6) << hitX << ": j = " << j << ", vel.y = " << std::setw(6) << z0(box.vel.y)
<< ", spin = " << std::setw(6) << z0(box.w) << " rad/s\n";
}
int main() {
std::cout << std::fixed << std::setprecision(3);
for (double x : {0.0, 0.25, 0.5, -0.5}) land(x);
}hit at x = 0.000: j = 2.400, vel.y = 0.400, spin = 0.000 rad/s
hit at x = 0.250: j = 1.745, vel.y = -0.255, spin = 2.618 rad/s
hit at x = 0.500: j = 0.960, vel.y = -1.040, spin = 2.880 rad/s
hit at x = -0.500: j = 0.960, vel.y = -1.040, spin = -2.880 rad/s
Read the rows top to bottom. A hit under the center gives the full bounce (vel.y flips from -2 to +0.4, which is e = 0.2) and no spin. The further out the contact, the smaller the impulse: part of the "push" turns into rotation. With a corner hit, only the contact point bounces; the center of mass keeps falling at about 1 m/s while the box tips over, exactly what a crate does when it lands on one corner. A hit on the left corner spins it the other way. Real landings have two or more contact points at once, which is why the next lessons solve several contacts together.
What engines expose
| Concept | Unity (PhysX) | Unreal (Chaos) | Godot | Box2D v3 |
|---|---|---|---|---|
restitution e |
PhysicsMaterial.bounciness |
Physical Material "Restitution" | PhysicsMaterial.bounce |
shapeDef.material.restitution |
| combine rule | bounceCombine (Average, Minimum, Multiply, Maximum) |
Physical Material "Restitution Combine Mode" | absorbent flag |
the world's restitution callback |
| apply an impulse | AddForce(j, ForceMode.Impulse) |
AddImpulse(j) |
apply_impulse(j) |
b2Body_ApplyLinearImpulse |
Both bodies have their own material, so engines need a combine rule to get one e for the pair. Unity defaults to Average and Box2D to the maximum of the two, so a superball stays bouncy on any floor.
Note: Restitution should vanish at low speeds. A resting box that keeps a tiny
e · vnbounce never settles. Engines therefore ignore restitution below a threshold speed (Box2D'srestitutionThreshold, PhysX's bounce threshold, about 1–2 m/s). Your own solver needs the same rule.
Test yourself
Two bodies have relative normal velocity vn = +1.5 (they are moving apart). What impulse should the solver apply?
-(1 + e) * 1.5 / (1/mA + 1/mB)- None: separating contacts get no impulse
- An impulse that stops them
- Twice the normal impulse
How does an engine model an immovable floor in the impulse formula?
- With a mass of 0
- With an inverse mass (and inverse inertia) of 0
- By skipping contacts with the floor
- With restitution 0
With restitution e = 0, what happens to two colliding bodies along the contact normal?
- They bounce apart at the same speed
- They end with the same normal velocity, and momentum is still conserved
- Both stop completely
- The lighter one stops