How to Apply Brake Friction in Ammo.js

This article explains how brake friction is applied to individual wheels within the Ammo.js physics engine’s vehicle system. It covers the mechanics of the raycast vehicle model, the specific API methods used to trigger braking, and how these forces translate to deceleration through tire-to-ground contact.

In Ammo.js—which is a direct JavaScript port of the Bullet Physics engine—vehicles are typically simulated using the btRaycastVehicle class. Instead of simulating complex, rigid-body wheel geometry spinning on physical axles, the system uses raycasting to detect the ground beneath each wheel. Suspension, steering, engine force, and braking are all calculated mathematically and applied as forces to the vehicle’s chassis.

The setBrake Method

To apply brakes to a wheel in Ammo.js, you use the setBrake method on your btRaycastVehicle instance. The method signature requires two arguments:

vehicle.setBrake(brakeForce, wheelIndex);

How the Physics Engine Processes Brake Friction

When you call setBrake(brakeForce, wheelIndex), Ammo.js does not physically squeeze a brake caliper. Instead, it alters the wheel’s constraint equations during the physics step:

  1. Rotation Constraint: The applied brakeForce acts as a limit on the wheel’s angular velocity. It exerts a counter-torque opposing the direction of the wheel’s rotation.
  2. Longitudinal Friction: The engine calculates the slip ratio of the tire (the difference between the wheel’s rotational speed and the actual forward speed of the vehicle body over the ground).
  3. Force Transfer: Based on the tire’s grip parameters (configured via wheelInfo.set_m_frictionSlip()) and the downward load from the suspension, the engine converts this rotational resistance into a linear braking force applied at the contact point with the ground.

If the brakeForce exceeds the maximum static friction threshold between the tire and the ground, the wheel “locks up.” When a wheel locks, its rotational speed drops to zero, and the vehicle enters a slide governed by the tire’s dynamic friction coefficient.