Hi
I have a project where i clone an existing entity twice in the project.
var templateCoin10 = pc.app.root.findByName('Coin 10');
var instanceCoin = templateCoin10.clone();
instanceCoin.setPosition(new pc.Vec3(0, 0.452, 0));
pc.app.root.addChild(instanceCoin);
instanceCoin.enabled = true;
var instanceCoin2 = templateCoin10.clone();
instanceCoin2.setPosition(new pc.Vec3(0, 0.452, 3));
pc.app.root.addChild(instanceCoin2);
instanceCoin2.enabled = true;
The initial entity has a script attached that check collision, and destroy if needed :
var Coin = pc.createScript('coin');
Coin.attributes.add('speed', { type: 'number', default: 30 });
Coin.prototype.initialize = function() {
console.log('Coin.prototype.initialize');
this.sound = this.entity.sound;
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
Coin.prototype.update = function(dt) {
this.entity.rotateLocal(0, this.speed * dt, 0);
};
Coin.prototype.onCollisionStart = function (result) {
console.log('onCollisionStart: ', result.other.name);
if (result.other.rigidbody && result.other.name === 'People') {
this.entity.collision.enabled = false;
this.entity.children[0].enabled = false;
this.entity.children[1].particlesystem.play();
this.sound.play('note');
setTimeout(() => {
console.log('destroy: ', this.entity._guid);
this.entity.destroy();
}, 1000);
}
};
The problem is when the user fire collision with one coin, the others one also disappear…