Matter.js Velocity Iterations and Projectile Accuracy

In Matter.js, the physics engine relies on iterative solver loops to calculate how forces, impulses, and constraints interact during collisions. Reducing the engine's velocity iterations lowers CPU load, but it significantly degrades the simulation accuracy of high-speed projectiles. This article examines how lowering this parameter leads to unrealistic rebound angles, erratic momentum conservation, increased clipping, and compromised ballistic trajectories.

The Role of Velocity Iterations

Matter.js uses a rigid-body physics pipeline where collision resolution occurs over two main phases: position iterations and velocity iterations. While position iterations correct body overlaps and penetration, velocity iterations resolve the impulses necessary to reflect restitution (bounciness) and friction.

By default, Matter.js sets engine.velocityIterations to 4. Each iteration refines the velocity vectors of colliding bodies until an equilibrium is reached. Lowering this value means the impulse solver halts its calculations early, accepting an approximation of linear and angular velocity rather than a physically correct solution.

Inaccurate Momentum Transfer and Rebound Angles

High-speed projectiles deliver large amounts of kinetic energy over a fraction of a millisecond. When a fast projectile strikes a surface, the impulse required to push it back or halt it is extremely high.

With reduced velocity iterations:

Exacerbated Tunneling and Penetration

Matter.js uses discrete collision detection rather than continuous collision detection (CCD). Bodies jump from one discrete point to another based on their velocity vector and the delta time step.

When velocity iterations are reduced:

Trajectory Drift and Multi-Body Inconsistencies

Reducing velocity iterations causes cumulative numerical errors when a projectile interacts with complex environments:

Balancing Performance and Accuracy

Reducing velocity iterations is a standard optimization technique for low-end hardware or scenes with hundreds of slow-moving entities. However, applying this reduction in scenes involving high-speed projectiles creates noticeable physics anomalies. To preserve ballistic accuracy without overburdening the CPU, developers should keep velocity iterations at or above default levels and instead optimize high-speed interactions by reducing the engine time step (engine.timing.delta), using sub-stepping, or implementing raycast-based collision checks for projectile paths.