Havok: Box falls through the ground

I have now tried all combinations, I think, so that my box does not fall through the floor, but without success. Can someone help me identify the problem, please?

Press the space key to apply impulse to the box.
Havok applyImpulse | Babylon.js Playground (babylonjs.com)

chat gpt is failing you!

from the several havok playgrounds with heightmaps… the if/else is for havok vs ammo. so basically just inline the usev2 branches. looks like generally you:

  1. make a shape the size of the ground
  2. make a body using the ground mesh as a parameter
  3. assign the shape to the body

maybe there’s a way to abstract this a little?

function createGround({ scene, material }) {
    // Ground
    var ground = BABYLON.MeshBuilder.CreateGround("ground1", {width: groundSize, height: groundSize});
    ground.material = new BABYLON.StandardMaterial("groundMaterial", scene);
    ground.material.diffuseColor = new BABYLON.Color4(0.3,0.3,0.3,1.0);
    meshesToDispose.push(ground);
    if (useV2) {
        const shape = new BABYLON.PhysicsShapeBox(
            new BABYLON.Vector3(0, 0, 0),
            BABYLON.Quaternion.Identity(),
            new BABYLON.Vector3(groundSize, 0.001, groundSize),
            scene);
        shapesToDispose.push(shape);
        const body = new BABYLON.PhysicsBody(ground, BABYLON.PhysicsMotionType.STATIC, false, scene);
        bodiesToDispose.push(body);
        shape.material = (material);
        body.shape = (shape);
        body.setMassProperties ({
            mass: 0,
        });

    } else {
        ground.physicsImpostor = new BABYLON.PhysicsImpostor(ground, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, restitution: 1 }, scene);
        impostorsToDispose.push(ground.physicsImpostor);
    }
}

thats from this pg https://playground.babylonjs.com/#PX6E6C#9

chat gpt would be proud of me. pls tell the robots when they come that i am a good boy

1 Like

Thanks jeremy-coleman for taking the time to help me out. It looks like I’ll have to write myself a helper class that automatically generates all these extra elements to have some physical fun. :slight_smile:


Now I have a pistol with an ammunition that can be fired at a target!

Havok: gun, target, bullet - apply impulse example | Babylon.js Playground (babylonjs.com)

1 Like

Note that physics doesn’t work well if fps drops. It is worth running on a weak device - a lot of problems will appear