mesh.checkCollisions issue

Hello everyone!

I have a very simple scene:
const scene = new Scene(engine);
scene.gravity = GRAVITY;
scene.collisionsEnabled = true;

const hemisphericLight = new HemisphericLight('hemispheric_light', new Vector3(0, 1, 0), scene);
hemisphericLight.intensity = 0.7;

const ground = Mesh.CreateGround('ground', 100, 100, 4, scene);
ground.checkCollisions = true;

const block1 = Mesh.CreateBox('block1', 2, scene);
block1.position.x = -3;
block1.checkCollisions = true;

const block2 = block1.clone('block2');
block2.position.x = 3
block2.checkCollisions = true;

The problem I am experiencing is that when the player moves in the scene, he can move through block1, but not block2. The weird part is that there is an area in between the blocks that the player is colliding with, which I assume is block1. After a couple hours of reading the forums, it has been determined that changing block1.ellipsoidOffset does nothing because only the moving mesh’s ellipsoid is used in collisions against the colliding meshes verts or bounding box.

In another forum topic, I found that using computeWorldMatrix may help, and it did, calling it directly after block1.checkCollisions = true;

This would mean that I will need to call computeWorldMatrix for any mesh where the position has changed. Which is fine, if iterating over the scene’s meshes and calling it for everything, but isn’t this called at render time?

Thank you in advance - I will try to put together a PG demo of this…

[EDIT]: Created a PG: https://playground.babylonjs.com/#P0WVKT

This PG does not replicate my issue. I did leave out that my issue is a server-side implementation using NullEngine - I wonder if that has anything to do with it?

Hey and welcome!!

As NullEngine is not rendering you have to force the world Matrices computation by calling block1.comptueWorldMatrix() after changing its position (same for block2 of course)

That makes perfect sense. Thank you :slight_smile:

1 Like