Physics Engines Overview

Babylon.js provides several physics engine options through a plugin architecture:

  • Cannon.js: Lightweight physics engine with good performance-to-accuracy balance
  • Oimo.js: Fast physics engine optimized for performance over accuracy
  • Ammo.js: Powerful engine (WebAssembly port of Bullet Physics) with advanced features
  • Havok: Commercial-grade physics with premium performance (requires license)

Each engine offers different trade-offs between performance, accuracy, feature set, and ease of use. For most projects, Cannon.js provides a good balance and is the recommended starting point.

// Import the physics engine (Cannon.js example)
// In HTML: <script src="https://cdn.babylonjs.com/cannon.js"></script>
// Or in modules: import * as CANNON from 'cannon';

// Enable physics with Cannon.js
const gravityVector = new BABYLON.Vector3(0, -9.81, 0);
const physicsPlugin = new BABYLON.CannonJSPlugin();
scene.enablePhysics(gravityVector, physicsPlugin);