this._physicsEngine.removeImpostor is not a function

this._physicsEngine.removeImpostor is not a function at _PhysicsImpostor._init (physicsImpostor.ts:527:29)

import { PhysicsEngine, HavokPlugin } from '@babylonjs/core/Physics';
import HavokPhysics from '@babylonjs/havok';

async function createScene() {
  // Create the engine and scene
  const canvas = document.getElementById('renderCanvas');
  const engine = new Engine(canvas, true);
  const scene = new Scene(engine);

  // Initialize Havok Physics
  const havok = await HavokPhysics();
  const plugin = new HavokPlugin(undefined, havok);
  scene.enablePhysics(new Vector3(0, -9.81, 0), plugin);

  // Create a ground plane
  const ground = MeshBuilder.CreatePlane("ground", { width: 10, height: 10 }, scene);
  ground.physicsImpostor = new PhysicsImpostor(ground, PhysicsImpostor.BoxImpostor, { mass: 0 }, scene);

  // Create a box
  const box = MeshBuilder.CreateBox("box", { width: 1, height: 1, depth: 1 }, scene);
  box.position.y = 2;
  box.physicsImpostor = new PhysicsImpostor(box, PhysicsImpostor.BoxImpostor, { mass: 1 }, scene);

  // Create a camera
  const camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0, 5, -10), scene);
  camera.setTarget(BABYLON.Vector3.Zero());
  scene.activeCamera = camera;

  // Start the render loop
  engine.runRenderLoop(() => {
    scene.render();
  });
}

createScene();```

note:  "@babylonjs/core": "^8.11.0",
    "@babylonjs/loaders": "^8.11.0",
    "socket.io-client": "^4.8.1",
    "vite": "^6.3.5",
    "@babylonjs/havok": "^1.3.10"

What you declared is Physics v2, and PhysicsImpostor is implemented based on Physics v1.

3 Likes

so, is there a method that equal to PhysicsImpostor in Physics v2? or must i use legacy version (v1)

cc @Cedric

It’s possible to dispose the mesh and attached physics body will be disposed as well. Or simply dispose the physics body and this will keep the mesh: