Default Friction Value in Matter.js Bodies

When simulating 2D physics in web applications using the Matter.js engine, understanding default physical properties is essential for predictable behavior. In a Matter.js body, the default value for standard kinetic friction is 0.1. This article explains how Matter.js handles friction by default, covers related friction properties like static and air resistance, and demonstrates how to customize these settings for rigid bodies.

The Default Friction Value

In Matter.js, the standard friction property defines the kinetic (sliding) friction of a rigid body. When a body is instantiated without explicitly specifying this property, the engine assigns it a default value of 0.1.

Friction values typically range from 0 to 1:

When two bodies collide or slide against one another, Matter.js calculates the effective friction between them using the minimum value of both bodies: Math.min(bodyA.friction, bodyB.friction).

Matter.js distinguishes between different types of friction. Alongside the standard kinetic friction, bodies feature two additional friction settings:

Setting Custom Friction

To override the default friction values, pass the desired configurations into the options object when creating a body:

const box = Matter.Bodies.rectangle(400, 200, 80, 80, {
  friction: 0.05,       // Custom kinetic friction (default: 0.1)
  frictionStatic: 0.2, // Custom static friction (default: 0.5)
  frictionAir: 0.005   // Custom air resistance (default: 0.01)
});

You can also modify the friction dynamically during runtime using Matter.Body.set:

Matter.Body.set(box, 'friction', 0.8);