How do dynamic bodies behave in planck.js?

In a planck.js simulation, a dynamic body is a fully simulated rigid body that reacts to external forces, gravity, and collisions with other objects. Unlike static or kinematic bodies, dynamic bodies possess mass and rotational inertia, allowing them to accelerate, bounce, slide, and rotate according to realistic Newtonian physics. This overview explores how these bodies interact within the physics engine, their key properties, and how developers can manipulate them for interactive applications.

Core Characteristics of Dynamic Bodies

A dynamic body is the most computationally intensive object type in planck.js because the engine must calculate its position and velocity at every simulation time step.

Collision and Interaction

When a dynamic body collides with another object in the simulation, planck.js resolves the collision based on the material properties of both participating fixtures:

Friction and Restitution

Friction determines how easily two surfaces slide against each other, while restitution (bounciness) determines how much kinetic energy is retained after a collision. A dynamic body colliding with a high-restitution static floor will bounce upward, losing a portion of its energy based on the combined restitution coefficient.

Interaction Types

Sleeping and Performance Optimization

Because computing physics for dozens of dynamic bodies can be CPU-heavy, planck.js includes a “sleeping” mechanism. When a dynamic body comes to rest and stops interacting with moving objects, the engine puts it to sleep.

While asleep, the body is excluded from the physics update loop, saving valuable processing power. The engine automatically wakes the body up if another moving object collides with it, or if a developer applies a force or changes its velocity via code.