Destroying an entity when it is stopped

Hello, I am a new Play Canvas member and I am not quite sure what code to use in my situation. I need to destroy an entity if it stops for 5 seconds. Is it possible to do that? (Also I have an urgent project due, so if someone could please answer me )

@Ishika_Saha This will depend on two different situations. Cloning or just enable/disable an entity in your hierarchy. This is the section of the API reference which should provide you with a good overview.

https://developer.playcanvas.com/api/pc.Entity.html

For timers I would take a look at these posts:
https://forum.playcanvas.com/search?q=Timers

This is a specific timer to destroy a cloned object/entity:

    setTimeout(function(){ 
        bullet.destroy();
    },100);

This is a disable which make the entity disappear:

// Enter trigger
ItemPickup.prototype.onTriggerEnter = function(object) {

    if(object.tags.has('player')) {

        // play the pickup sound
        if(this.entity.sound) this.entity.sound.play("Pickup");
              
        // increase the munitions amount
        console.log("pickup");

        // Increase item amount
        object.fire("player:addhealth",this.amount);

        // Disable after Pickup
        this.entity.enabled = false;
           
    }

};

Hope this helps. Posting a link to your project will enable others to help you debug if you have issues.

2 Likes