Setting Up Physics
Configure the physics environment for your scene:
// Setup physics with Havok (recommended)
import HavokPhysics from '@babylonjs/havok';
// Initialize Havok WASM module
const havokInstance = await HavokPhysics();
// Create physics plugin
const gravityVector = new BABYLON.Vector3(0, -9.81, 0);
const havokPlugin = new BABYLON.HavokPlugin(true, havokInstance);
// Enable physics in the scene
scene.enablePhysics(gravityVector, havokPlugin);
// Configure physics engine properties
const physicsEngine = scene.getPhysicsEngine();
physicsEngine.setTimeStep(1/60); // Fixed timestep for stable simulation