[Havok ] New plugin physics "HK" is not defined

I wanted to try this new Havok physics engine which is an incredible engine. But my first try failed.

Maybe I rushed too quickly and not everything was deployed.

I get an error here:

const havok = new BABYLON.HavokPlugin(true); // Error hpInjection
scene.enablePhysics(new BABYLON.Vector3(0, -9.81, 0), havok);

I added the file: HavokPhysics_umd.js

And I have this error :

caught (in promise) ReferenceError: HK is not defined
at new HavokPlugin (babylon.max.js?1682022887:218628:39)

did you add Havok?
https://cdn.babylonjs.com/havok/HavokPhysics_umd.js

Yes, I added it locally from the zip

it has to go first. can you share a repro?

PG is working: PhysicsV2 Add Bodies | Babylon.js Playground (babylonjs.com)

So you should miss one reference somehow

image

In the playground it works.

I saw this on the forum: Should I also add this?

globalThis.HK = await HavokPhysics();

Maybe that’s my oversight. Because it is not indicated in the documentation that this must be added.

That should not be the case. @Cedric @carolhmj @RaananW

In the meantime please use your hack (to define HK). We will fix that asap

2 Likes

Should be soon fixed here Havok Plugin Documentation and Instantiation · Issue #13765 · BabylonJS/Babylon.js · GitHub

3 Likes

Is there no node-ish way to add Havok atm?

edit: Found @babylonjs/Havok - I assume that’s it?

2 Likes

yep :slight_smile:

You can see an example here :blush:

there is no change though - it still says

ReferenceError
HK is not defined
Call Stack
 new HavokPlugin
  vendors-node_modules_qoretechnologies_reqore_dist_index_js-node_modules_storybook_addon-actio-12a578.iframe.bundle.js:427451:61
 StorybookGameHandler._setupEngine
  main.iframe.bundle.js:152:101

Do I need to import the HavokPlugin from @babylonjs/core or HavokPhysics from @babylonjs/havok ?

Check the code example, it will explain everything.
I’ll write the full docs tomorrow
You need to initialize the engine and pass it as a variable to the plugin itself. Second variable.

Full docs tomorrow, promised :grin:

1 Like

I corrected it like this at home :

async createScene()
{ 
...

const gravity = new BABYLON.Vector3(0, -10, 0);
const hk = await HavokPhysics();
const babylonPlugin =  new BABYLON.HavokPlugin(true, hk);
scene.enablePhysics(gravity, babylonPlugin);
}

add the HavokPhysics_umd.js and HavokPhysics.wasm files in the same directory locally

And in the htaccess file I put
AddType application/wasm wasm

And it works

7 Likes

Just following up on this one:

Using Havok and the Havok Plugin | Babylon.js Documentation (babylonjs.com)

4 Likes