What is Ammo.js ERP and How Does It Stabilize Joints?

This article explains the role of the Error Reduction Parameter (ERP) in ammo.js, a WebAssembly port of the Bullet physics engine. You will learn what ERP is, how it mathematically influences constraint resolution, and how to configure it alongside Constraint Force Mixing (CFM) to eliminate joint stretching, jitter, and simulation instability.

Understanding the Error Reduction Parameter (ERP)

In physics simulations, joints (or constraints) connect rigid bodies together. Due to numerical rounding errors and the discrete time-stepping nature of physics engines, connected bodies inevitably drift apart over time. This drift is known as positional error.

The Error Reduction Parameter (ERP) determines what fraction of this positional joint error is corrected during the next simulation step. ERP accepts a value between 0.0 and 1.0:

How ERP and CFM Work Together

To achieve stable joints, ERP is almost always paired with Constraint Force Mixing (CFM). While ERP acts as a restoring force that pulls joints back together, CFM defines the softness or elasticity of the joint.

In the constraint equation, CFM adds a positive value to the diagonal of the system matrix. This allows the joint to violate its constraints slightly, acting like a damper. When combined:

Stabilizing Joints in Ammo.js

To prevent joints from breaking or shaking uncontrollably in ammo.js, you must tune the ERP based on your simulation’s needs.

  1. Adjust the Global ERP: You can set the global ERP for the entire physics world using the world’s solver properties. If your joints are stretching too much under heavy loads, slightly increasing the global ERP can help pull them back into place.
  2. Configure Individual Joint Limits: Ammo.js allows you to set ERP and CFM values on individual constraints (such as btHingeConstraint or btGeneric6DofConstraint). Use the setParam method with the parameter constants BT_CONSTRAINT_ERP and BT_CONSTRAINT_CFM to fine-tune specific joints.
  3. Match with Time Steps: ERP is highly dependent on your simulation time step. If you decrease your physics step size (e.g., from 1/60s to 1/120s), you may need to lower your ERP to prevent the joint-restoring forces from overcorrecting and causing high-frequency vibrations.