Physics Engines Overview
Babylon.js provides several physics engine options through a plugin architecture:
- Havok (Recommended): The default physics engine since Babylon.js 6.0. A WebAssembly-based, commercial-grade physics engine that is free and MIT-licensed for web use. Offers up to 20x faster performance over legacy engines and is the only engine supported by the modern Physics V2 API.
- Cannon.js (Legacy V1 only): Lightweight physics engine with good performance-to-accuracy balance
- Oimo.js (Legacy V1 only): Fast physics engine optimized for performance over accuracy
- Ammo.js (Legacy V1 only): WebAssembly port of Bullet Physics with advanced features
Important: The Physics V1 API (PhysicsImpostor) is deprecated. The current recommended approach uses the Physics V2 API (PhysicsAggregate, PhysicsBody, PhysicsShape) with the Havok engine. All examples below use the modern Physics V2 API.
// Install Havok: npm install @babylonjs/havok
import HavokPhysics from '@babylonjs/havok';
// Initialize Havok (async)
const havokInstance = await HavokPhysics();
// Enable physics with Havok
const gravityVector = new BABYLON.Vector3(0, -9.81, 0);
const havokPlugin = new BABYLON.HavokPlugin(true, havokInstance);
scene.enablePhysics(gravityVector, havokPlugin);