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

**URL:** <https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049>\
**Category:** Bugs\
**Tags:** physics\
**Created:** [April 20, 2023, 8:56pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049 "2023-04-20T20:56:05Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 20, 2023, 8:56pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/1 "2023-04-20T20:56:05Z")

</div>

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:

```auto
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)

 ![2023-04-20 22_51_37-Greenshot](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/8/c86db863286b59cc656ec7840ffde2539c79385a.jpeg)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:11pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/2 "2023-04-20T21:11:42Z")

</div>

did you add Havok?  
[https://cdn.babylonjs.com/havok/HavokPhysics\_umd.js](https://cdn.babylonjs.com/havok/HavokPhysics_umd.js)

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 20, 2023, 9:13pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/3 "2023-04-20T21:13:10Z")

</div>

Yes, I added it locally from the zip

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:13pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/4 "2023-04-20T21:13:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:14pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/5 "2023-04-20T21:14:52Z")

</div>

PG is working: [PhysicsV2 Add Bodies | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#RQIZD3#1)

So you should miss one reference somehow

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:15pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/6 "2023-04-20T21:15:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/5/85edcaa358801f1579b6a747870d3eaf087657c7.png)

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 20, 2023, 9:16pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/7 "2023-04-20T21:16:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:17pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/8 "2023-04-20T21:17:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 9:20pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/9 "2023-04-20T21:20:26Z")

</div>

> [@Dad72](#):
>
> .HK = await HavokPhysics();

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 20, 2023, 9:31pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/10 "2023-04-20T21:31:26Z")

</div>

Should be soon fixed here [Havok Plugin Documentation and Instantiation · Issue #13765 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/issues/13765)

---

<div class="post-metadata">

**Author:** ![Foxhoundn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/foxhoundn/32/15613_2.png) [@Foxhoundn](https://forum.babylonjs.com/u/Foxhoundn)\
**Post date:** [April 20, 2023, 11:01pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/11 "2023-04-20T23:01:08Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [April 20, 2023, 11:03pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/12 "2023-04-20T23:03:04Z")

</div>

yep 🙂

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 20, 2023, 11:06pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/13 "2023-04-20T23:06:11Z")

</div>

> <https://github.com/RaananW/babylonjs-webpack-es6/blob/master/src/scenes/physicsWithHavok.ts>

You can see an example here 😊

---

<div class="post-metadata">

**Author:** ![Foxhoundn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/foxhoundn/32/15613_2.png) [@Foxhoundn](https://forum.babylonjs.com/u/Foxhoundn)\
**Post date:** [April 20, 2023, 11:07pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/14 "2023-04-20T23:07:30Z")

</div>

there is no change though - it still says

```auto
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` ?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 20, 2023, 11:21pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/15 "2023-04-20T23:21:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 20, 2023, 11:21pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/16 "2023-04-20T23:21:48Z")

</div>

Full docs tomorrow, promised 😁

---

<div class="post-metadata">

**Author:** ![Dad72](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dad72/32/13_2.png) [@Dad72](https://forum.babylonjs.com/u/Dad72)\
**Post date:** [April 20, 2023, 11:23pm UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/17 "2023-04-20T23:23:27Z")

</div>

I corrected it like this at home :

```auto
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

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [April 24, 2023, 10:16am UTC](https://forum.babylonjs.com/t/havok-new-plugin-physics-hk-is-not-defined/40049/18 "2023-04-24T10:16:52Z")

</div>

Just following up on this one:

[Using Havok and the Havok Plugin | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/physics/havokPlugin)
