Hey @Igor, an approach I’ve used to detect collision:
var Collider = pc.createScript('collider');
//SUMMARY
//this script is used to detect a collision between entity (that has attached script) and any other object that has a rigid body
//only triggers when a new object starts a collision
//when collision event occurs, message printed to console and entity changes color (as long as it has a material attached)
// initialize code called once per entity
Collider.prototype.initialize = function () {
//collision logic gets triggered whenever a new collision event is detected (afer incoming object left this entity's collision area)
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
// collision logic
Collider.prototype.onCollisionStart = function (result) {
if (result.other.rigidbody) {
console.log('collision success');
this.entity.model.material.diffuse.set(Math.random(), Math.random(), Math.random());
this.entity.model.material.update();
}
};
*I’ve used this logic in my test game (ie. “Collider.js” script)
*Note: Both entities would need to have “rigid body” and “collision” components
Thank you for the answer, @Vdizzle! But it’s a bit different, collisionstart event appears only once when collision begins. But I would like to know how to get list of entity’s collisions at any moment. Is it possible in PlayCanvas at all or I need to dig into Ammo.js docs?