Problem with Ammo.js

Hello, I’ve been using the simple code below for months and everything worked and now I get these errors:

babylon.js:16 BJS - [22:12:42]: AmmoJS is not ready. Please make sure you await Ammo() before using the plugin.
e._ErrorEnabled @ babylon.js:16

BJS - [22:12:42]: Cannot read property ‘setValue’ of undefined
e._ErrorEnabled @ babylon.js:16

babylon.js:16 BJS - [22:12:42]: Physics not enabled. Please use scene.enablePhysics(…) before creating impostors.

e._ErrorEnabled @ babylon.js:16

What can I do, please? How to fix it? Thank you in advance.

my code:

            physEngine = new BABYLON.AmmoJSPlugin(false);
            scene.enablePhysics(new BABYLON.Vector3(0, -9.8, 0), physEngine);

            terenPhysics.physicsImpostor = new BABYLON.PhysicsImpostor(terenPhysics, BABYLON.PhysicsImpostor.MeshImpostor, {mass: 0, friction: 10});
            sphereMetal.physicsImpostor = new BABYLON.PhysicsImpostor(sphereMetal, BABYLON.PhysicsImpostor.SphereImpostor, {mass: 1, friction: 10});

physEngine.setTimeStep(1/110);
scene.physicsEnabled = false;

As the message mentioned in the error, you need to initialize ammo before creating the plugin.

await Ammo(); or Ammo().then(() => { ... }

Unfortunately, this is the only way to stay uptodate with Ammo as they changed their li in their latest version.

1 Like

Am I doing this wrong? Await f(x)'s are confusing…

scene.enablePhysics(new BABYLON.Vector3(0, -1, 0), new BABYLON.AmmoJSPlugin(true));
        Ammo().then(() => {
        arm = BABYLON.MeshBuilder.CreateBox(
          "arm",
          { width: 40, depth: 1, height: 1 },
          scene
        );
        arm.position = new BABYLON.Vector3(0, 10, -9);
        arm.physicsImpostor = new BABYLON.PhysicsImpostor(
          arm,
          BABYLON.PhysicsImpostor.BoxImpostor,
          { mass: 0, friction: 0, restitution: 0 },
          scene
        );

        //doubleside (?)
        var cloth = BABYLON.MeshBuilder.CreateGround(
          "cloth",
          {
            width: 30,
            height: 30,
            subdivisions: 40,
            sideOrientation: BABYLON.Mesh.DOUBLESIDE
          },
          scene
        );
        cloth.position.x = 0; // arm.position.x*0.5;
        cloth.position.y = arm.position.y * 0.5;
        cloth.position.z = 0; //arm.position.z*0.5;
        cloth.rotation.x = Math.PI / 2;

        cloth.physicsImpostor = new BABYLON.PhysicsImpostor(
          cloth,
          BABYLON.PhysicsImpostor.ClothImpostor,
          {
            mass: 10,
            friction: 0,
            restitution: 0,
            damping: 0.01,
            margin: 0.15
          },
          scene
        );
        cloth.physicsImpostor.velocityIterations = 10;
        cloth.physicsImpostor.positionIterations = 10;
        cloth.physicsImpostor.stiffness = 0.026; //.6

        cloth.physicsImpostor.addAnchor(arm.physicsImpostor, 0, 0, 1);
        cloth.physicsImpostor.addAnchor(arm.physicsImpostor, 1, 0, 1);

        var pbr = new BABYLON.PBRMaterial("pbr", scene);
        cloth.material = pbr;
        arm.material = pbr;

        pbr.albedoColor = new BABYLON.Color3(1.0, 0.766, 0.336);
        pbr.metallic = 1.0; // set to 1 to only use it from the metallicRoughnessTexture
        pbr.roughness = 1.0; // set to 1 to only use it from the metallicRoughnessTexture
        pbr.subSurface.isRefractionEnabled = true; //is this doing anything (?)
        pbr.reflectionTexture = BABYLON.CubeTexture.CreateFromPrefilteredData(
          "/textures/environment.dds",
          scene
        );
        pbr.metallicTexture = new BABYLON.Texture("/textures/mr.jpg", scene);
        pbr.useRoughnessFromMetallicTextureAlpha = false;
        pbr.useRoughnessFromMetallicTextureGreen = true;
        pbr.useMetallnessFromMetallicTextureBlue = true;
        pbr.alpha = 0.25;
          
          });
        /////////

I still get this: AmmoJS is not ready. Please make sure you await Ammo() before using the plugin.

Yes, ammo() needs to be called before creating physics so your first line shoild be in the callback.

1 Like

Ok that fixed it, now a dumb question, is there a cdn to get textures outside of the playground?

I’m trying to get a dds file working on glitch, but glitch won’t let me upload it as an asset, so I have to link to it directly.

there’s this, Using External Assets In the Playground | Babylon.js Documentation, but I want to go the other way

update: lol nm found it!

1 Like