Sensing a collision

the “onTriggerEnter” Function is not working:

pc.script.create(‘brick’, function (app) {
// Creates a new Brick instance
var Brick = function (entity) {
this.entity = entity;
};

Brick.prototype = {
    // Called once after all resources are loaded and before the first update
    initialize: function () {
        console.log('hi this is sensing as');
        this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
    },

     onTriggerEnter: function (entity) {
        // Reset back to roughly the position the entity started in.
        
       console.log('hi this is sensing');
       
       var mover = app.root.findByName('Player');
       mover.script.moving.reseter();
    }
    
    
  
};

return Brick;

});

Read tutorial: http://developer.playcanvas.com/en/tutorials/intermediate/collision-and-triggers/
And read documentation: http://developer.playcanvas.com/en/api/pc.CollisionComponent.html

Player will be non - static rigidbody. Static rigidbodyes and collisions without rigidbody don’t recieves collision events. Attach ontriggerenter event on Player script.

2 Likes