Let me start with a disclosure: I only started learning JavaScript few weeks ago, the error I encountered might be due to shortcomings in my understanding of JS and / Babylon. Be gentle.
I’m trying to get Cannonjs to play with Babylonjs. As far as I understand (see this thread) this should work:
import { BabylonFileLoaderConfiguration } from “babylonjs”;
import * as foo from “cannon”;
BabylonFileLoaderConfiguration.LoaderInjectedPhysicsEngine = foo;
Unfortunately, I’m only getting Cannot set property 'LoaderInjectedPhysicsEngine' of undefined.
The full source code is split across couple of files, and I’m not clever enough (yet!) to make it work with the playground. I uploaded class producing the above error to pastebin here.
@sebavan can correct me if I’m wrong, but I think this should work. What version of ‘babylonjs’ are you using? The BabylonFileLoaderConfiguration wasn’t added until about 4 months ago.
Both cannon and babylonjs are freshly installed via npm yesterday:
"babylonjs": "^4.0.3",
"cannon": "^0.6.2"
I’m very much new to the world of JS, and Babylonjs I only discovered few days ago - more than likely it is error on my side. I’m following Isaias Pomales tutorial which can be found here. My repo - which results in the said error - can be found here.
As I couldn’t figure out where I did mistake, I tried using @babylonjs/core and loading cannon via webpack - works exactly as advertised!
What makes me think that the mistake here is mine is the weird physics on the working version. I isolated the issue to the physics being applied in the ‘ground’ class. It might be related to the Cannot set property 'LoaderInjectedPhysicsEngine' of undefined error but honestly, I don’t know enough (yet!) to be sure of that. The working version using @babylonjs/core lives in this branch, and I think that the offending file is Ground.js.
If someone could take a look at that file and tell me where did I messed up I’ll be grateful. This thing is driving me up the wall
Can I be cheeky? Could you have a look at the sort-of-working branch of the same repo? I got cannon to work there with @babylonjs/core via webpack. But… the physics itself is like something out of a Lovecraft novel
I think that the issue there is with how the PhysicsImpostor is being created in Ground.js - but I can’t figure out how to fix it.