Meshes falling through ground created from non regular height map (rectangle not square)


I am developing an environment which uses a non regular heightmap, one that is rectangular in a 2:1 ratio, as opposed to a usual square; blame the customer. Creating the mesh using BABYLON.MeshBuilder.CreateGroundFromHeightMap works fine. Problem arises when I apply a BABYLON.PhysicsImpostor.HeightmapImpostor. Some falling meshes collide as expected but others slip through the ground.

I have adapted a version of the “Heightmap demo physics engine” on the playground to illustrate the point:

The only change I have made is to line 19 swapping out 200 for 100 as the first option making the ground mesh rectangular, and meshes fall through the world. Change it back to 200, square ground mesh, and everything works fine.

Previous attempts have involved:

  1. Using two heightmaps offset side by side but these produced a very ugly seam down the middle.

  2. Using a square heightmap with alpha and using the alphaFilter option set to 1. This produced a usable mesh but the physics imposter failed to read the alpha areas resulting in meshes hanging in mid air.

Query: How do you apply a physics engine to a rectangular heightmap?

I’ve run out of ideas.

Thanks in advance.


Yeah, this is a limitation of the current heightmap implementation in cannon. You can create a feature-request on our github, and we will look into that when we get the chance.

A different approach - use ammo as a physics engine and define the heightmaps as a mesh using the MeshImpostor:

Heightmap demo physics engine gone wrong | Babylon.js Playground (


Thanks for the quick response. I switched physics engines as you suggested and once I had sorted the await Ammo() issue everything now functions as expected. Cheers.