How to use AmmoJSPlugin when working with TypeScript

Hi, I’m very confused when trying to follow documentation for how to get AmmoJS running in my TypeScript/Webpack project. The documentation seems to imply that I need to npm install ammojs, but only if I’m working with AmmoJS directly as opposed to this implementation found in babylon.module.d.ts:

image

I have declared a variable like so:

image

And I have setup my physicsEngine and imposters like so:

and naturally, cos it’s TypeScript it automates the following imports:

It all compiles fine, but in the browser I get an empty screen and this appears in my console:

image

I’ve even followed the kripken solution mentioned in the docs and here and still no luck because then it asks for type definitions which don’t seem to exist.

What am I doing wrong? I can’t find anything in documentation to clarify on this process.

pinging @sebavan

import * as Ammo from 'ammo.js';
...
const gravity = new Vector3(0, -9.81, 0);
this.scene.enablePhysics(gravity, new AmmoJSPlugin(undefined, Ammo));

You get that error, because the plugin is looking for ammo and you didn’t pass it in. I think otherwise you need a global declaration.

1 Like