Cannot detect collisions (but can detect intersections)

Hello.

I have a scene with a player (an imported mesh - a .glb file) and a cube (default BJS box mesh).

I am using moveWithCollisions to move the player.
The cube has collisions enabled. cube.checkCollisions = true.

As expected, my player cannot “walk through the cube”. :+1:

However, my problem is that I am not being able to detect “when my player collides against the cube”.

I tried using onCollideObservable, but it did not help.
cube.onCollideObservable.add(() => { console.log('Player has collided with me!') })

What am I doing wrong?

P.S. If I remove cube.checkCollisions, the player will walk right through the cube - thereby triggering player.intersectsMesh(cube). That’s not what I want.

A rather messy solution that I can think of is creating an invisible box all around the cube that is slightly bigger in size (than the cube itself).

This wrapper mesh won’t have checkCollisions enabled, so the player can walk right through it.

This would trigger player.intersectsMesh(cubeWrapper).

I would then be able to call any callback method attached to the wrapper mesh (something like cubeWrapper.data.callback).

Since, intersectsMesh will get called in every frame in which “the player is inside the wrapper mesh”, I shall have to manually ensure that the callback method gets triggered only once.

Like I said, this solution is messy and I really, really, really want to avoid doing things like this. :sob:

Do you have the scene set to use collisions?

scene.collisionsEnabled = true;

I have reason to believe that it is enabled by default.
In any case, I did try setting that explicitly; it did not work.

Can you show in a playground? Would be much easier to help. Thanks