How Restitution 1.0 Behaves in Matter.js
In Matter.js, the restitution property dictates the
elasticity or bounciness of a rigid body during impacts. Assigning a
restitution value of 1.0 defines a perfectly elastic collision,
theoretically conserving 100% of the body's kinetic energy when it
strikes another surface. This article explains how the 1.0 restitution
value interacts with other physics bodies in the engine, why external
factors like friction affect the outcome, and how to achieve true
perpetual bouncing.
Collision Resolution Logic
Matter.js determines collision elasticity using the higher
restitution value between two colliding bodies. By default, the engine
applies Math.max(bodyA.restitution, bodyB.restitution) to
compute the collision response. Because of this formula:
- If Body A has a restitution of
1.0and strikes Body B with a restitution of0.0, the collision is still treated as fully elastic (1.0). - The body rebounds with its full post-collision velocity without any energy dissipation directly caused by the impact itself.
The Impact of Default Drag and Friction
A common misconception is that a restitution of 1.0 will cause an object to bounce indefinitely under standard engine settings. While the collision itself does not absorb kinetic energy, Matter.js bodies include default values for drag and surface friction that bleed energy continuously:
frictionAir: Defaults to0.01. This acts as atmospheric drag, gradually reducing the body's linear and angular velocity every update frame.friction: Defaults to0.1. When bodies slide against each other during non-perpendicular impacts, this value converts motion into friction losses.frictionStatic: Defaults to0.5, introducing resistance when a body begins sliding along another surface.
To achieve an object that bounces perpetually without losing height or speed, these properties must be explicitly disabled:
const bouncer = Bodies.circle(x, y, radius, {
restitution: 1.0,
friction: 0,
frictionAir: 0,
frictionStatic: 0
});Numerical Stability and Edge Cases
Because Matter.js is an iterative, discrete-time physics engine, minor anomalies can occur when restitution is set to 1.0:
- Energy Creep or Decay: Rounding errors across
multiple frames can subtly alter an object's energy over prolonged
simulations. Increasing
engine.positionIterationsandengine.velocityIterationsreduces this drift. - Restitution Above 1.0: While 1.0 is the physical threshold for full energy conservation, Matter.js allows values greater than 1.0, which injects kinetic energy into the system on every impact, causing objects to accelerate exponentially after each bounce.
- Resting Threshold: At very low velocities, the engine's sleep and resting thresholds may override elasticity to prevent micro-jittering when an object settles.
A restitution value of 1.0 is most commonly utilized in arcade-style mechanics, such as Pong or Breakout clones, pinball bumpers, and elastic particle simulations where realistic energy dampening is undesirable.