CollisionEnd Pop Up Boxes Doesn't Close After Being Triggered. How to fix?

Is there something wrong with my code? The collisionend doesn’t work every time I walk away from the object, the infoboxes are still on display.

Here are my codes:

FirstPersonView.prototype.OnCollisionEnter = function(result){
    if (result.other.name == "ZodiacRat") {
        this.app.root.findByName("infobox").enabled = true;
    }
    if (result.other.name == "ZodiacPig") {
        this.app.root.findByName("infobox").enabled = true;
    }
}

FirstPersonView.prototype.OnCollisionEnd = function(result){
    if (result.other.name == "ZodiacRat") {
        this.app.root.findByName("infobox").enabled = false;
    }
    if (result.other.name == "ZodiacPig") {
        this.app.root.findByName("infobox").enabled = true;
    }
}

FirstPersonView.prototype.initialize = function() {

this.entity.collision.on("collisionstart", this.OnCollisionEnter, this);

this.entity.collision.on("collisionEnd", this.OnCollisionEnd, this);

var app = this.app;

Hi @zero2,

The event ids are case-sensitive so instead of collisionEnd try collisionend to begin with.

https://developer.playcanvas.com/en/api/pc.CollisionComponent.html#event:collisionend

1 Like

this still doesn’t work.

Hi @zero2!

Not sure on which entity you are testing, but shouldn’t line 15 above be false instead of true?

If that doesn’t solve the problem, can you please share the editor link of your project?

1 Like

Hi! It only worked for the rat, but for the other objects, they don’t appear even when triggered by the collision. I tried it with the ones that are not part of the circle. The figures on the corners has pop up infoboxes but they don’t show up.

Hi! It only worked for the rat, but for the other objects, they don’t appear even when triggered by the collision. I tried it with the ones that are not part of the circle. The figures on the corners has pop up infoboxes but they don’t show up.

Do you know what might be wrong in my code? Thanks so much!

Shared it with you.

It seems you already solved the problem by changing result.other.name to result.name on collisionend. It remains difficult to remember when you should and should not use other.

Yes, but for some reason, it doesn’t work with the others. It only works with certain animals, but doesn’t work with everything. Do you know what might be wrong?

Here’s my code so far:

FirstPersonView.prototype.OnCollisionEnter = function(result){
    if (result.other.name == "ZodiacRat") {
        this.app.root.findByName("infobox").enabled = true;
    }
    if (result.other.name == "ZodiacPig") {
        this.app.root.findByName("infobox1").enabled = true;
    }
    if (result.other.name == "ZodiacDragon") {
        this.app.root.findByName("infobox2").enabled = true;
    }
    if (result.other.name == "ZodiacHare") {
        this.app.root.findByName("infobox3").enabled = true;
    }
    if (result.other.name == "ZodiacOx") {
        this.app.root.findByName("infobox4").enabled = true;
    }
    if (result.other.name == "ZodiacSnake") {
        this.app.root.findByName("infobox5").enabled = true;
    }
}

FirstPersonView.prototype.OnCollisionend = function(result){
    if (result.name == "ZodiacRat") {
        this.app.root.findByName("infobox").enabled = false;
    }
    if (result.name == "ZodiacPig") {
        this.app.root.findByName("infobox1").enabled = false;
    }
    if (result.name == "ZodiacDragon") {
        this.app.root.findByName("infobox2").enabled = false;
    }
    if (result.name == "ZodiacHare") {
        this.app.root.findByName("infobox3").enabled = false;
    }
    if (result.name == "ZodiacOx") {
        this.app.root.findByName("infobox4").enabled = false;
    }
    if (result.name == "ZodiacSnake") {
        this.app.root.findByName("infobox5").enabled = false;
    }
}```

If it works with one and not with the other, while the code and setup are the same, then I don’t know what could be the cause unfortunately.