onCollide not triggering

Hey all, Im trying to run the onCollide function without any success…

Not sure if I got it correctly, but if I got, it is just an event that we add to a impostor, right? If is that so, why this isnt working? Babylon.js Playground

In this example I would expect that the log "aqui" would popup when the sphere collided with the ground, but when it collides nothing happens.

Does anyone know what am I doing wrong? :thinking:

You need to either register a collision callback to a specific impostor, or use the onCollideEvent:

onCollide not working | Babylon.js Playground (babylonjs.com)

Hey @RaananW , thank you for your fast answer! I just don’t get a thing about it

In your examples you didn’t used the onCollide method, I think I still don’t get exactly how to use it, also readed that onCollideEvent is legacy, but it really is?

I was looking for a way to do the event without needing the ground, but Im not sure how to do so since onCollideEvent is legacy, Im sorry, I think Im kinda confused now :rofl:

onCollide is a function that is actually executed by the physics engine itself, so you shouldn’t override it.
onCollideEvent is what you are looking for - no need to mention the mesh you collide again. However, performance-wise, it is better to filter the meshes the element collides against that are passed to the callback. This is very apparent when you have many impostors.