Density, friction, and restitution

As you already know how to add bodies to the world, I want to introduce you to three attributes that will affect bodies' behavior: density, friction, and restitution.

The density is used to set the mass of a body, measured in kilograms by square meter. Higher density means heavier bodies, and it can't be negative.

The friction comes into play when two bodies slide on each other, and it's defined by a coefficient, usually from 0 (no friction) to 1 (strong friction). It can't be negative.

The restitution determines how much a body will bounce after a collision. Like density and friction, it can't be negative and it's defined by a coefficient usually from 0 to 1. A ball falling on the ground with restitution zero ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.