Detecting Collision Between Two Specific Objects

Hi,

Struggling to figure out how to detect a collision between two specific rigid bodies.

My code –

    // Creates a new Collider instance
    var Collider = function (entity) {
        this.entity = entity;
    };
    Collider.prototype = {
        // Called once after all resources are loaded and before the first update
        initialize: function () {
            this.entity.collision.on('collisionstart', this.onCollisionStart, this);
        },
        onCollisionStart: function(result){
            if(result.other.//entityName){
                alert("collision detected");
            }
        }
        
        
    };
    return Collider;
});```

Try this:

var Collider = pc.createScript('collider');

// initialize code called once per entity
Collider.prototype.initialize = function () {
    this.entity.collision.on('collisionstart', this.onCollisionStart, this);
    
//name of 1st object
        this.Entity1 = this.app.root.findByName('Entity1');

//name of 2nd object
        this.Entity2 = this.app.root.findByName("Entity2");
};

Collider.prototype.onCollisionStart = function (result) {
    
    //Check to see if Entity1 has hit this object
    if (result.other.name == this.Entity1) {
        
        //Do something here
        console.log("you hit me!!");
    }

};

Thanks a ton, will try that

i also had the same problem