How to Make Ammo.js Objects Frictionless and Bouncy

In ammo.js, the physics engine commonly used alongside 3D libraries like Three.js, achieving a perfectly frictionless yet highly bouncy object requires configuring specific physical properties on the rigid body. This article provides a direct, step-by-step guide on how to set an object’s friction to zero and its restitution (bounciness) to its maximum value, ensuring perfect elastic collisions without any kinetic energy loss from surface drag.

Step 1: Set Friction to Zero

To remove all surface resistance when the object slides against other surfaces, you must set its friction, rolling friction, and spinning friction to 0. In Ammo.js, this is done using the rigid body’s setter methods:

// Assuming 'rigidBody' is your Ammo.btRigidBody instance
rigidBody.setFriction(0f);
rigidBody.setRollingFriction(0f);
rigidBody.setSpinningFriction(0f);

Step 2: Set Restitution to Maximum

Restitution controls the bounciness of an object. A value of 1.0 represents a perfectly elastic collision, meaning the object will bounce back with the same amount of kinetic energy it had before the impact.

rigidBody.setRestitution(1.0);

Step 3: Configure the Colliding Surfaces

In Ammo.js, collision behavior is calculated by combining the physical properties of both interacting objects. If your frictionless, bouncy object collides with a ground plane that has default friction (usually 0.5) and zero restitution, the bounce will be dampened, and friction will still occur.

To achieve a truly frictionless and highly bouncy interaction, you must also apply these properties to the surfaces your object will collide with:

// Apply the same properties to the ground or obstacle rigid body
obstacleBody.setFriction(0);
obstacleBody.setRollingFriction(0);
obstacleBody.setRestitution(1.0);

Adjusting the Physics World Solver (Optional)

If you notice energy loss over time despite setting restitution to 1.0, it may be due to the physics world’s default constraint solver or damping. You can disable linear and angular damping on your moving object to ensure it never loses momentum in a vacuum:

// Disable air resistance / damping (linear, angular)
rigidBody.setDamping(0, 0);