Need some help initialization havok engine

Hello guys, while learning BBjs im working on some physics concepts.
After reading and follow the related docs:
havok plugin
So now Im trying to initialize the engine so I can use later into the plugin but im having following console error message:

RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 3c 21 44 4f @+0). Build with -sASSERTIONS for more info.
    at abort (@babylonjs_havok.js?v=501b91be:298:15)
    at @babylonjs_havok.js?v=501b91be:367:11

I will share the class I created:

import {
} from "@babylonjs/core";
import "@babylonjs/loaders";
import HavokPhysics from "@babylonjs/havok";

export class LeoScene {
  scene: Scene;
  engine: Engine;

  constructor(private canvas: HTMLCanvasElement) {
    this.engine = new Engine(this.canvas, true);
    this.scene = this.createScene();
    this.engine.runRenderLoop(() => {

    const scene = new Scene(this.engine)
    return scene;

  async setScene(canvas:HTMLCanvasElement){
    const camera = new ArcRotateCamera("Camera", Math.PI/1.5,Math.PI/4, 50, new Vector3(0, 0, 0), this.scene);
    // camera.setPosition(new Vector3(0, 0, -10));
    camera.attachControl(canvas, true);
    const light = new HemisphericLight("light", new Vector3(0, 1, 0), this.scene);{ overlay: true });

  async  getInitializedHavok() {
    return await HavokPhysics();

Im using vite starter script.
I already did the npm install @babylonjs/havok

Last question … can I try cannon intead or is it not recommended ?
Any suggestion / idea would be wellcome,

I would greatly recommend to use this template - GitHub - minibao/babylon-vite
It will give answers to all your abovementioned questions :slight_smile:
Here is the example of Havok initialozation:

 async _setPhysics(): Promise<void> {
    const gravity = new Vector3(0, -9.81, 0)
    const hk = await HavokPhysics()
    const plugin = new HavokPlugin(true, hk)
    this.scene.enablePhysics(gravity, plugin)

The last update of Cannon.js was 9 years ago. Havok physics engine is much more better in all terms.

1 Like

thanks my friend … it is working now !!!