Matter.js Body Friction Property Explained
In Matter.js, the friction property dictates the kinetic
(sliding) resistance of a rigid body when it moves against another
body's surface. This article explains how the friction
property operates, how its values influence motion, how friction is
calculated during collisions between two surfaces, and how it contrasts
with static and air friction properties in the physics engine.
Kinetic Friction Mechanics
The friction property represents dynamic or sliding
friction. When an object is in direct contact with another body and
moving across it, kinetic friction exerts an opposing force parallel to
the contact surface, causing the object to decelerate and eventually
come to a stop.
Values and Defaults
- Default Value: The default value is
0.1. - Value Range: The property typically uses a range
between
0.0and1.0, although values greater than1.0are allowed to simulate extreme resistance. 0.0(Frictionless): The body behaves like an object on perfectly slick ice, sliding continuously across surfaces without losing momentum from surface contact.1.0(High Friction): The body experiences significant resistance, halting sliding motion almost immediately upon contact.
How Matter.js Resolves Collision Friction
Friction is never calculated in isolation. When two bodies touch, Matter.js calculates an effective friction for the interaction. By default, the engine determines the combined friction using the minimum value of the two colliding bodies:
\[\text{Effective Friction} = \min(\text{bodyA.friction}, \text{bodyB.friction})\]
Because of this calculation, if one body has a friction
value of 0, the contact pair will behave frictionlessly,
regardless of how high the friction value is on the second body.
Comparison With Other Friction Properties
Matter.js provides three distinct friction settings on a body:
friction(Dynamic Friction): Applies strictly when two bodies are already sliding against each other in physical contact.frictionStatic: Dictates the threshold of force required to transition a stationary object into a sliding state. A higher static friction prevents an object resting on an inclined plane from starting to slide.frictionAir: Represents linear drag or air resistance. Unlikefriction, it operates on the body continuously, even when it is airborne and making no contact with other surfaces.