Impostor Types
Different collision shapes for different needs:
Babylon.js provides several impostor types for different collision needs:
- BoxImpostor: Simple box collision - efficient for rectangular objects
- SphereImpostor: Spherical collision - most efficient, good for round objects
- CylinderImpostor: Cylindrical collision - for tubes, pillars, etc.
- MeshImpostor: Uses actual mesh geometry - most accurate but computationally expensive
- HeightmapImpostor: Efficient for terrain - uses height data for collision
- ConvexHullImpostor: Creates simplified collision from mesh vertices - good balance
- ParticleImpostor: Point with mass but no rotation - for simple particles
- NoImpostor: For compound objects with child impostors
For performance, always use the simplest collision shape that adequately represents your object.
// Complex mesh with accurate collision
const complexMesh = BABYLON.MeshBuilder.CreateTorusKnot("tk", {}, scene);
complexMesh.position.y = 10;
// Options for different collision types
// 1. Exact mesh collision (expensive)
complexMesh.physicsImpostor = new BABYLON.PhysicsImpostor(
complexMesh,
BABYLON.PhysicsImpostor.MeshImpostor,
{ mass: 3, restitution: 0.4 },
scene
);
// 2. Convex hull (better performance)
complexMesh.physicsImpostor = new BABYLON.PhysicsImpostor(
complexMesh,
BABYLON.PhysicsImpostor.ConvexHullImpostor,
{ mass: 3, restitution: 0.4 },
scene
);
// 3. Simple approximation (best performance)
complexMesh.physicsImpostor = new BABYLON.PhysicsImpostor(
complexMesh,
BABYLON.PhysicsImpostor.SphereImpostor,
{ mass: 3, restitution: 0.4 },
scene
);