[SOLVED] How to use Collision & Time?

So me and a friend have been working on a game for quite some time. We want to add an attack that, when the opposing player touches you and you’re pressing a certain button, they die. Same thing vise versa. We also want to integrate time. Basically you have to wait 30 seconds to re-activate or to use this attack again. We’ve been searching the docs for quite some time, but we’re not sure how we make this concept a reality. Can someone help explain how to use collision and time to create this attack?

Link to the editor: https://playcanvas.com/editor/scene/848105

Hi @DevPrimeOG,

Try using this -

var Time = pc.createScript('time');

// initialize code called once per entity
Time.prototype.initialize = function() {
    this.disable = 0;
};

// update code called every frame
Time.prototype.update = function(dt) {
    this.disable += dt;

    if (this.disable > 10) {
        this.disabled() = true;
    }    

    else{
       this.disable = false;
    }
}; 

Forgive my indentation since I’m on mobile.

Thanks for the script. We’ve figured out how to make the attack work. Gonna put it as solved.

1 Like

You’re welcome @DevPrimeOG. Glad it works.

1 Like