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:
- ERP = 0.0: The engine applies no corrective force to fix positional drift. Over time, the joint will stretch and pull apart permanently under gravity or external forces.
- ERP = 1.0: The engine attempts to correct 100% of the joint drift in a single physics step. While this sounds ideal, it usually introduces massive, abrupt forces that cause explosive jitter, instability, and physics crashes.
- ERP = 0.1 to 0.8 (Typical Range): A moderate value
(the default is usually
0.2) allows the engine to resolve the drift gradually over several frames, ensuring smooth and stable motion.
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:
- High ERP and Low CFM create a very stiff, rigid joint that snaps back to its origin quickly.
- Low ERP and High CFM create a soft, springy, or rubber-like joint that tolerates a lot of stretch and dampens sudden movements.
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.
- 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.
- Configure Individual Joint Limits: Ammo.js allows
you to set ERP and CFM values on individual constraints (such as
btHingeConstraintorbtGeneric6DofConstraint). Use thesetParammethod with the parameter constantsBT_CONSTRAINT_ERPandBT_CONSTRAINT_CFMto fine-tune specific joints. - 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.