Detecting Collisions Between Two Specific Objects

Hi folks, I would like to know if it’s possible (and if so, how) to detect collisions between two specific objects, instead of merely detecting any collision with any object.

To detect a collision with any object and have such a collision trigger a function, I would have been using this in my entity.prototype.initialize function script:

this.entity.collision.on('triggerenter',
this.onTriggerEnter, //Function to call
this);

However, I do not know how to detect when two specific objects collide, such as in the case of https://playcanvas.com/project/483854/overview/tinkering-project-1, where I need to be able to differentiate a collision with the side walls and a collision with a moving box (for the Sphere), and run certain functions when the moving box touches the sphere. How, and can I do that?

Thanks in advance.

Have you looked in documentation about other events there are for collision component? https://developer.playcanvas.com/en/api/pc.CollisionComponent.html

1 Like