Im not really sure what I am doing wrong, it looks like await havokModule in the example is simply returning a new HavokPlugin with no arguments, and Im just kind of at a loss of how this works?
Also scene.enablePhysics is trying to say it does not exist on the Scene class, which is confusing me as well.
Could use just a little bit of insight on what I am doing wrong here.
I tried that as well, I’m running typescript so I get all those warnings.
And in in the example they are initializing it as a module without a new or arguments. Which is kinda confusing. In the example from the docs there are two different accessible methods that act different, and I’m not sure what’s the correct usage.
Here is my setup as its not a super simple process… most of this was kit bashed from the docs + forum posts where others stumbled on the setup too.
You will also need the webworker WASM in your webpage root. It seems to generate on first install of havok’s package (and on updates) in your root distro folder. If you need it let me know.
----havok.ts there is nothing else in this ts except the below----
// HAVOK initialization by RaananW https://github.com/RaananW/babylonjs-webpack-es6/blob/master/src/externals/havok.ts
import HavokPlugin from "@babylonjs/havok";
export const havokModule = HavokPlugin();
—Everything below is in the main engine initialization class—
import "@babylonjs/core/Physics/physicsEngineComponent";
import { havokModule } from "./havok";
---in the main engine initialization constructor----
constructor(){
let preTasks = [havokModule]; // FYI pretasks never gets directly called, this just loads the module to memory
}
public async init(){
… more obviously
rb.scene.enablePhysics(null, new HavokPlugin(true, await havokModule)); //<–HERE Initialized HAVOK to my rb.scene
… more obviously
}
You’re right, but it feels like you’re complicating things here, and it really boils down to this.
import Havok from "@babylonjs/havok"
import {HavokPlugin} from "@babylonjs/core"
//on init
scene.enablePhysics(null, new HavokPlugin(true, await Havok()));
This was always critical for me to get things working. It needs to be in your init() before anything else for the module to properly load. My code may have looked “overly complex” (and yes, the process could use simplified!) but otherwise things don’t work and instead you get lots of strange errors.