How Angular Damping Prevents Infinite Rotation in Ammo.js
This article explains how angular damping functions within the ammo.js physics engine to stop 3D objects from rotating indefinitely. You will learn the underlying physics principles of rotational resistance, how the engine calculates velocity decay over time, and how to configure damping properties in your JavaScript code to achieve realistic physical simulations.
In a default physics simulation, objects obey Newton’s first law of motion: an object in motion stays in motion unless acted upon by an external force. In ammo.js—a direct port of the Bullet Physics engine—applying torque to a rigid body will cause it to spin forever if there are no external forces, collisions, or friction acting against it. This frictionless environment often results in unrealistic behavior, such as floating items or debris spinning endlessly in space.
Angular damping solves this problem by simulating atmospheric resistance or internal rotational friction. It acts as a continuous drag force that specifically targets an object’s angular velocity. Every time the physics engine updates (each simulation tick), it reduces the object’s rotational speed by a fraction determined by the angular damping coefficient.
Mathematically, the engine applies a decay factor to the angular velocity vector. The formula used during each step of the simulation behaves similarly to:
\[\text{New Angular Velocity} = \text{Current Angular Velocity} \times (1.0 - \text{Angular Damping} \times \text{Time Step})\]
Through this exponential decay, even a small damping value will gradually slow down a spinning object until its rotational velocity reaches zero, bringing it to a natural stop.
In ammo.js, developers can control this behavior using the
setDamping method on a btRigidBody instance.
This method accepts two parameters: linear damping (for
translation/forward movement) and angular damping (for rotation).
// Map values typically between 0.0 (no damping) and 1.0 (maximum damping)
let linearDamping = 0.1;
let angularDamping = 0.5;
rigidBody.setDamping(linearDamping, angularDamping);An angular damping value of 0.0 allows for eternal
spinning, while a value closer to 1.0 creates heavy
resistance, making the object stop spinning almost immediately after
torque is removed. Implementing appropriate damping values is essential
for creating believable interactions for common game objects like
rolling dice, falling crates, or vehicles.