I have a question about triggerenter

I’m trying to handle a triggerenter event that starts with a rigidbody attached at the beginning and then removes the rigidbody with a script after a few seconds, but it doesn’t work.
Is this not supposed to be done?

If I don’t attach the rigidbody in the editor, the trigger event works fine.

The reason I want to do this is so that the item is picked up after falling out of the air at the beginning of the game.

Looking for help!

var ItemBox = pc.createScript('itemBox');

ItemBox.prototype.initialize = function () {

    this.entity.collision.on("triggerenter", this.getItem, this);

    this.isRemove = false;
    this.removeTime = 2;

ItemBox.prototype.update = function (dt) {

        this.removeTime -= dt;
        if(this.removeTime <= 0){
            this.removeTime = 2;
            this.isRemove = true;

ItemBox.prototype.getItem = function (result) {

    if (result ) {

Hi @Sibuya_Ryu and welcome!

That’s probably because a trigger entity cannot have a rigidbody component. Instead of triggerenter you can use collisionstart.


1 Like