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?

EDIT: Here’s a PG that kind of shows the problem. We cannot detect more than one collision per move. The engine detects them all - you can’t walk through any solid object - but it only calls onCollision on one of them.

That’s a problem in my game where I try walk through a “portal” (which triggers a scene change), but detect only “floor” 99.9% of the time. The portal absolutely blocks movement, but its onCollision is never called, so I can’t change levels.

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…

Can someone please explain how the slide-after-collision logic works? I mean, if only the first collision is reported, what stops the mesh from passing through other meshes, e.g. when it’s in contact with more than one obstacle?
Not sure whom to ping, but looks like @Cedric and @sebavan have written much of the collider code.

moveWithCollision is limited and quite slow now compared to modern physics engine. Is there a reason why you are using Physics like Havok?

Mostly I’m afraid of the big breaking changes of moving to a completely different movement system. Also, some doubt that physics can really be faster than mWC, but that’s based on BJS 6-era physics.

But I’m getting really tired of fighting mWC issues, so maybe it’s time to bite the bullet…