Running NullEngine in node.js to leverage the Havok physics engine

Hi all, I’m new here. I’ve been slowly entering the independent game developer space over the past few years, and one of the major roadblocks I’ve encountered is getting a real-time collision engine up and running in an authoritative-server architecture. With the integration of the Havok physics engine into Babylon, I wanted to ask for the community’s opinions, advice, and comments on the feasibility of leveraging the Havok engine on my server.

Does the NullEngine provide access to the Havok engine at this time? Is it feasible to leverage it for tracking game-world collision detection? My strategy would be to use the Havok engine as a stand-alone resource in my server to handle collision detection, collision event dispatch, and object position and orientation. The actual physics may or may not use the Havok engine, as my games focus more on arcade physics than simulated physics, and I don’t know that much about the Havok engine yet.

So in general, I want to populate the Havok engine with my game objects and let it handle collision detection on the game server. There are other features I would need and I’m not sure yet if they are included in the Havok plugin, like client-side interpolation, the Havok AI tools and the Havok Cloth simulation tools. Regardless, just getting the collision engine checked off the list would be a huge step forward for me.

I would really appreciate any feedback, comments, or tips that anyone could provide. I am at the point in my development where I want to nail down the technology stack so I can move forward with creating a working infrastructure.

1 Like

That s a pretty good question. Let me add @RaananW and @Cedric to this thread.

You can use Havok without a renderer because it’s not using a GPU.
This said, doing physics synchronization on the network is a complicated topic.
It’s a job on its own in game studios.
Here is some overview and related topics:

Even doing a simple falling body simulation + sync looks like a daunting task to me.


A small note - The Havok package might not be consumed correctly by node. This is because emscripten is adding references to fs and path in order to get that to work, and that leads to an issue for people compiling their project for the web. There are ways around it, but we wanted the default configuration to be web friendly. It depends on your build process.

"dependencies": {
    "@babylonjs/core": "^6.4.1",
    "@babylonjs/havok": "^1.0.1"
HK = require("@babylonjs/havok");


When I try to run this inside node I get this error below.

Aborted(both async and sync fetching of the wasm failed)
failed to asynchronously prepare wasm: RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.
Aborted(RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.)
Uncaught RuntimeError RuntimeError: Aborted(both async and sync fetching of the wasm failed). Build with -sASSERTIONS for more info.
    at abort (HavokTest\node_modules\@babylonjs\havok\lib\umd\HavokPhysics_umd.js:9:6495)
    at getBinary (HavokTest\node_modules\@babylonjs\havok\lib\umd\HavokPhysics_umd.js:9:7021)
    at <anonymous> (HavokTest\node_modules\@babylonjs\havok\lib\umd\HavokPhysics_umd.js:9:7451)
    at processTicksAndRejections (internal/process/task_queues:96:5)

Is this because of the emscripten references? if so how do I build it so it works in a node environment for the null engine?

Have you checked this out?


Thank you for the help, I believe it worked :smiley: !

I followed the post you linked and just straight up injected the binary, and while I cannot see the sphere bouncing off the ground the console output shows the y position moving up and down which is enough confirmation for me lol.

thank you again for the help!

*in my previous post I was using UMD format by accident I meant to use ESM which I switched to now

const wasm = path.join(__dirname, 'node_modules/@babylonjs/havok/lib/esm/HavokPhysics.wasm');
let binary = fs.readFileSync(wasm);
    //initialize physics plugin, NullEngine, etc


is this loaded in a node environment? Or for a web environment?

It’s loaded in a node environment

1 Like

then this is a perfect solution :slight_smile:

1 Like