Dynamic Objects falling through the ground

Objects fall through the ground, which should not be the case.
Below is the code that you can also see in the playground. Seems like I am missing something obvious, but after hours of looking into it, I don’t understand what is the problem. Please help.

const scene = new BABYLON.Scene(engine);
  scene.enablePhysics(new BABYLON.Vector3(0, -1, 0), new BABYLON.HavokPlugin());


// Camera 
const camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 1, -4), scene);

camera.attachControl(canvas, true);

// Light
new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0), scene);


// Ground
const ground = BABYLON.MeshBuilder.CreateGround("ground", { width: 100, height: 20 }, scene);
const groundAggregate = new BABYLON.PhysicsAggregate(ground, BABYLON.PhysicsShapeType.BOX, { mass: 0 }, scene);


// Cart
const cartMesh = BABYLON.MeshBuilder.CreateBox("cart", { height: 0.05, width: 0.4, length: 0.001 });
cartMesh.position = new BABYLON.Vector3(0, 1, 0);

const cartBody = new BABYLON.PhysicsBody(cartMesh, BABYLON.PhysicsMotionType.DYNAMIC, false, scene);
cartBody.setMassProperties({
  mass: 1,
});

// Pendulum 
const pendulumPivot = new BABYLON.TransformNode("pivot", scene);
pendulumPivot.rotation.z = 60 * Math.PI / 180; // Initial angle
pendulumPivot.parent = cartMesh;
const pendumpivotAggregate = new BABYLON.PhysicsAggregate(pendulumPivot, BABYLON.PhysicsShapeType.BOX, { mass: 0 }, scene)

const pendulumRod = BABYLON.MeshBuilder.CreateCylinder("rod", { height: 0.5, diameter: 0.02 }, scene);
pendulumRod.position = new BABYLON.Vector3(0, 0.25, 0); // Offset for pivot
pendulumRod.parent = pendulumPivot;

const pendulumBody = new BABYLON.PhysicsBody(pendulumRod, BABYLON.PhysicsMotionType.DYNAMIC, { mass: 2 }, scene);

return scene;

Cc @Cedric

pendulumBody and cartBody are just bodies, without a shape. No shape = no collision.
Create and attach a shape or use an agregate.
For linking 2bodies together, use a constraint.
Also, thanks for using a playground for sharing your code with use: click the save button and copy/paste the link.

3 Likes