If there are multiple colliders, which mesh becomes `collidedMesh`?

I have a bug (which I can’t replicate in a PG) where the player’s mesh.collider.collidedMesh.name is always “floor”, even when it also collides with a “wall”. The logic is pretty basic:

let disp = mesh.calcMovePOV(0, GRAVITY, speed)
mesh.moveWithCollisions(disp)
debugLabel.text = mesh.collider?.collidedMesh?.name

So my question is: since there can be only one collidedMesh, how does mWC decide which one to assign, when there is more than one?

What happens if you would add onCollideObservable to check - Babylon.js docs ?

Just tried it… It reports “floor” as well. That’s actually good - it’s consistent.

Remove the floor. Does it then collide with the wall?

The situation is not so simple :slight_smile:
Here is the draft PG - https://playground.babylonjs.com/#6E4LSB#108
Move the box, but after several collisions one always will finish only with cylinder.

1 Like

From what I could test, this way, you will get proper collision feedback:

1 Like

Seems that your mesh is a bit lower that the floor?

I’m not sure (how) that can happen. Gravity keeps the mesh as close to the terrain as the collisions allow, but no closer.

The root of the problem is that the collidedMesh is singular… The engine detects all collisions, but it’s limited to reporting one.

Detecting one collision works fine. The problem is detecting all collisions. The engine clearly does detect them (because it blocks movement), but collidedMesh can only point to one.

It seems that when you have a larger number of meshes, the decision of which one to report is not so clear/deterministic.

One solution I can think of is to use multiple collider meshes. One for ground detection, another for walls. But moveWithCollisions is slow already…