TExcelTAD

Friction

The impulse along the contact normal stops objects from passing through each other. Without anything else, every surface would be perfectly slippery: a crate on a ramp slides down forever and a car can't turn. Friction is a second impulse, applied along the contact tangent, that resists sliding.

Coulomb's model

Game engines use the classic Coulomb friction law:

  • The friction force acts along the surface, against the sliding direction.
  • Its size is at most μ · N, where N is the normal force pressing the surfaces together and μ is the coefficient of friction of the pair.
  • Static friction (μs) holds an object still as long as the needed force stays below μs · N. Once it slides, dynamic (kinetic) friction μd ≤ μs slows it.

In impulse form, the solver works with the normal impulse jn from the same contact instead of the force N:

  1. Compute the tangential relative velocity vt = dot(vRel, t), where t is the tangent (perpendicular to n).
  2. Compute the impulse that would stop sliding completely: jt = -vt / (1/mA + 1/mB) (plus the angular terms, exactly as for the normal impulse).
  3. Clamp it: jt = clamp(jt, -μ · jn, μ · jn).

If the clamp doesn't trigger, the contact sticks (static friction). If it does, the object keeps sliding with reduced speed (dynamic friction). The set of allowed friction impulses is a circle of radius μ · jn around the normal in 3D, the friction cone. Many engines approximate the cone with two independent tangent directions, which turns it into a square (a friction pyramid or box); the corners let a body resist slightly more diagonally than straight on, which nobody notices in a game.

Sliding to a stop

A crate thrown across the floor at 5 m/s with μ = 0.4. Each step: gravity pushes it into the floor, the normal impulse cancels that, and the clamped friction impulse removes speed. Physics says it decelerates at μ · g and stops after v² / (2 μ g) meters.

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

int main() {
    std::cout << std::fixed << std::setprecision(3);
    const double g = 9.81, mu = 0.4, dt = 1.0 / 60, m = 2.0;
    double vx = 5, vy = 0, x = 0;
    int step = 0;
    while (true) {
        vy -= g * dt;                                   // gravity pushes the crate into the floor
        double jn = std::max(0.0, -vy * m);             // normal impulse: cancel downward velocity
        vy += jn / m;
        double jt = -vx * m;                            // impulse that would stop sliding completely
        jt = std::clamp(jt, -mu * jn, mu * jn);         // Coulomb: at most mu * jn
        vx += jt / m;
        x += vx * dt;
        step++;
        if (step % 15 == 0 || vx == 0)
            std::cout << "t = " << step * dt << " s  vx = " << vx << "  x = " << x << "\n";
        if (vx == 0) break;
    }
    std::cout << "theory: stops after " << 5 / (mu * g) << " s and " << 25 / (2 * mu * g) << " m\n";
}
t = 0.250 s  vx = 4.019  x = 1.119
t = 0.500 s  vx = 3.038  x = 1.993
t = 0.750 s  vx = 2.057  x = 2.622
t = 1.000 s  vx = 1.076  x = 3.005
t = 1.250 s  vx = 0.095  x = 3.143
t = 1.283 s  vx = 0.000  x = 3.144
theory: stops after 1.274 s and 3.186 m

The simulation agrees with the formula to within one step (and about 1.3% in distance, the usual error of a 60 Hz integrator). Note the last step: when the remaining speed is smaller than what friction can remove, the clamp doesn't trigger, jt is exactly -vx · m, and the crate stops dead instead of sliding backward. That is static friction taking over, and it falls out of the clamp for free.

Stick or slide on a ramp

On a slope of angle θ, gravity splits into a part along the slope (g sin θ) and a part into it (g cos θ). The object stays put while tan θ ≤ μs. Engines with separate static and dynamic coefficients (PhysX does; Box2D and Jolt use one) pick μs while the contact sticks and μd once it slides:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>

// Simulate 1 s of a box on a ramp in the ramp's own frame: x along the slope (down), y along the normal.
void ramp(double degrees, double muS, double muD) {
    const double g = 9.81, dt = 1.0 / 60, m = 1.0, pi = 3.141592653589793;
    double th = degrees * pi / 180;
    double vx = 0, vy = 0, x = 0;
    bool everSlid = false;
    for (int i = 0; i < 60; i++) {
        bool stuck = (vx == 0);                       // at rest on the ramp at the start of the step?
        vx += g * std::sin(th) * dt;
        vy -= g * std::cos(th) * dt;
        double jn = std::max(0.0, -vy * m);
        vy += jn / m;
        double mu = stuck ? muS : muD;                // stuck: static friction; sliding: dynamic
        double jt = std::clamp(-vx * m, -mu * jn, mu * jn);
        if (jt != -vx * m) everSlid = true;
        vx += jt / m;
        x += vx * dt;
    }
    std::cout << std::setprecision(1) << std::setw(4) << degrees << " deg | " << std::setprecision(3) << "tan = " << std::tan(th) << " | "
              << (everSlid ? "slides" : "sticks") << " | moved " << x << " m, speed " << vx << " m/s\n";
}

int main() {
    std::cout << std::fixed << std::setprecision(3);
    std::cout << "muS = 0.6, muD = 0.4\n";
    for (double d : {20.0, 30.0, 30.9, 31.1, 45.0}) ramp(d, 0.6, 0.4);
}
muS = 0.6, muD = 0.4
20.0 deg | tan = 0.364 | sticks | moved 0.000 m, speed 0.000 m/s
30.0 deg | tan = 0.577 | sticks | moved 0.000 m, speed 0.000 m/s
30.9 deg | tan = 0.598 | sticks | moved 0.000 m, speed 0.000 m/s
31.1 deg | tan = 0.603 | slides | moved 0.840 m, speed 1.679 m/s
45.0 deg | tan = 1.000 | slides | moved 2.093 m, speed 4.139 m/s

Up to 30.9° the box holds (tan θ < 0.6). At 31.1° static friction gives way, and because dynamic friction is lower the box doesn't creep: it jumps straight to a real slide, accelerating at g (sin θ − 0.4 cos θ). Two tenths of a degree separate "stands still" from "slides 0.8 m in a second". This "breakaway" is why a player standing on a steep slope suddenly slides off, and why character controllers usually don't use friction at all (see Slopes, Steps and Ground Snapping).

Combining two materials

A contact has two surfaces, each with its own μ. Engines combine them with a rule, and the rules differ:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

int main() {
    std::cout << std::fixed << std::setprecision(3);
    struct Pair { const char* name; double a, b; };
    std::cout << "pair            | average | minimum | multiply | maximum | sqrt(a*b)\n";
    for (Pair p : {Pair{"ice / ice", 0.05, 0.05}, Pair{"ice / rubber", 0.05, 0.9}, Pair{"wood / rubber", 0.5, 0.9}, Pair{"wood / wood", 0.5, 0.5}}) {
        std::cout << std::left << std::setw(15) << p.name << std::right << " | " << std::setw(7) << (p.a + p.b) / 2 << " | "
                  << std::setw(7) << std::min(p.a, p.b) << " | " << std::setw(8) << p.a * p.b << " | "
                  << std::setw(7) << std::max(p.a, p.b) << " | " << std::setw(9) << std::sqrt(p.a * p.b) << "\n";
    }
}
pair            | average | minimum | multiply | maximum | sqrt(a*b)
ice / ice       |   0.050 |   0.050 |    0.003 |   0.050 |     0.050
ice / rubber    |   0.475 |   0.050 |    0.045 |   0.900 |     0.212
wood / rubber   |   0.700 |   0.500 |    0.450 |   0.900 |     0.671
wood / wood     |   0.500 |   0.500 |    0.250 |   0.500 |     0.500
Engine Friction settings Default combine
Unity (PhysX) PhysicsMaterial.staticFriction, dynamicFriction, frictionCombine Average
Unreal (Chaos) Physical Material "Friction", "Friction Combine Mode" Average (changeable in Project Settings)
Godot PhysicsMaterial.friction, rough minimum (or the rough body's value)
Box2D v3 shapeDef.material.friction sqrt(a * b) (overridable with a friction callback)
Jolt BodyCreationSettings::mFriction sqrt(a * b) (overridable)

The same pair of materials can feel very different from engine to engine. Notice that multiply makes wood on wood (0.25) slipperier than either surface alone, while the geometric mean keeps equal materials unchanged. When a level designer says "this ramp is too slippery", check the combine mode of both materials before touching the numbers.

Tip: Friction also needs a rolling and spinning counterpart for wheels and balls. Pure Coulomb friction lets a ball roll forever on flat ground because the contact point doesn't slide. Engines add rolling resistance (Box2D's rollingResistance in the surface material) or you add angular damping.

Test yourself

In an impulse solver, what limits the friction impulse at a contact?

  1. The tangential velocity
  2. μ times the normal impulse at the same contact
  3. The body's mass
  4. Restitution

A box rests on a 25° slope (tan 25° ≈ 0.47). Which static friction coefficient keeps it still?

  1. 0.3
  2. 0.4
  3. 0.5
  4. None, it always slides

Why can the same two physics materials feel different in Unity and Box2D?

  1. Box2D has no friction
  2. The engines combine the two coefficients with different default rules
  3. Unity ignores friction on dynamic bodies
  4. Box2D uses degrees