So I’m making a horror game and I have a big problem,
I’m trying to make it so that when the player runs over a trigger (like a mine) a scary duck entity appears can anyone help me with this perhaps a demo project?
I appreciate your help
So I’m making a horror game and I have a big problem,
I’m trying to make it so that when the player runs over a trigger (like a mine) a scary duck entity appears can anyone help me with this perhaps a demo project?
I appreciate your help
Here is a quick one I made:
var DuckAppearence = pc.createScript('DuckAppearence');
DuckAppearence.attributes.add('duck', {
type: 'entity',
description: 'the entity that enables/disables'
});
DuckAppearence.attributes.add('aNumber', {
type: 'number',
description: 'the number of milliseconds (1000 = 1 second)'
});
DuckAppearence.prototype.initialize = function() {
this.duck.enabled = false;
this.entity.collision.on('collisionstart', this.onCollisionStart, this);
};
DuckAppearence.prototype.onCollisionStart = function () {
setTimeout(() => {
this.duck.enabled = true;
}, this.aNumber);
this.duck.enabled = false;
};
if this one doesn’t work, please tell me, and I will work on the bugs. Cheers!
Update: I used collision start, not trigger enter. So, this one works better! when you collide with the entity that has this script, it will activate your duck, and it will disappear after the time amount you set it to. script:
var DuckAppearence = pc.createScript('DuckAppearence');
DuckAppearence.attributes.add('duck', {
type: 'entity',
description: 'the entity that enables/disables'
});
DuckAppearence.attributes.add('aNumber', {
type: 'number',
description: 'the number of milliseconds (1000 = 1 second)'
});
DuckAppearence.prototype.initialize = function() {
this.duck.enabled = false;
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
};
DuckAppearence.prototype.onTriggerEnter = function () {
this.duck.enabled = true;
setTimeout(() => {
this.duck.enabled = false;
}, this.aNumber);
};
edit: Here is a demo : PlayCanvas | HTML5 Game Engine . When the box collides with another box, it activates a fire for the set amount of time (in this case 5 seconds) after the 5 seconds, it is disabled.
yes.