API

Physics

Physics engines are third-party external programs that can be plugged into Babylon.js. Depending on their features, they emulate "real-life" interactions between objects, which can be meshes, solid particles from the solid particle system, or some cameras. One feature of a physics engine is the addition of gravity to a scene.

There are 2 physics architectures in Babylon.js.

We strongly recommend using V2 over V1. A migration guide is here.

Physics V2

There are plugins for 1 physics engine:

  1. Havok - a powerful engine used in AAA games.

It needs to be enabled before use.

This architecture allows finer-grained control over your physics scene by distinguishing between collision shapes and physical bodies. A typical use case is to have one collision shape used by numerous bodies. This allows a lower memory footprint and more efficient memory addressing. A special effort has been put into better performance for a huge number of bodies. This is also the case for the collision callback mechanism.

A broad overview of the Physics V2 advancements is available on this Medium article.

Physics V1

There are plugins for 3 physics engines:

  1. Cannon.js - a wonderful physics engine written entirely in JavaScript.
  2. Oimo.js - a JS port of the lightweight Oimo physics engine.
  3. Ammo.js - a JS port of the bullet physics engine.

All need to be enabled before use.

Interactions between objects are achieved by impostors, simple objects that are attached to complex objects in a scene. The impostor can be assigned physical attributes such as mass, friction, a coefficient of restitution, impulse, and linear and angular velocity.

Two imposters can be connected using joints such as a hinge or ball and socket.

Ammo also allows the creation of soft bodies.

Coming next

Aggregates
How to use Physics Aggregate for fast and easy physics scene creation.
Aggregates
Using Havok and the Havok Plugin
Learn how to use the Havok plugin offered by Babylon.js.
Using Havok and the Havok Plugin
Using A Physics Engine
Learn how to use one of the available physics engines in Babylon.js.
Using A Physics Engine
Physics V2 core concepts
All the concepts and objects designed for Physics V2 plugins
Physics V2 core concepts
Physics V2 Shapes
Describing Shapes
Physics V2 Shapes
Forces
Learn all about applying physical forces in Babylon.js.
Forces
Physics Compounds
Learn how to use compounds to model complex objects with simple primitives.
Physics Compounds
Collision Events
Learn how to access collision events in Babylon.js.
Collision Events
Constraints
Learn all about using Constraints with Babylon.js.
Constraints
Raycast
How to use Physics for fast raycasting.
Raycast
Migrate from Physics V1
A guide on best practices to port a Physics V1 scene to V2
Migrate from Physics V1
Performance Tips
A guide on best practices to achieve maximum performance with the Physics V2 API
Performance Tips
Ragdolls
A guide on ragdoll creation with the Physics V2 API
Ragdolls
Shape cast
A guide on shape casting with the Physics V2 API
Shape cast
Physics prestep
How to use prestep to apply changes from scene to physics world
Physics prestep
Physics character controller
How to use the character controller
Physics character controller