How to handle object overlaping

Hi to all, im new here and i have a couple of questions. Im struggling to make overlap functionality.

For example i create zone around the player or object or just place that zone on the map.
I want if i enter in that zone to show text and if i leave zone to hide that text.
The problem is body.touching is working only if the player is moving i assume its working on velocity only, and soon as i stop moving inside of zone text disappear because phaser doesn’t register body.touching.

Is there any way or trick to know if bodies/zones are overlapping/touching if im not moving inside of them?

Set the state?
As long as you haven’t moved out, you’re still in :smile:

So instead of checking body touching constantly, only use the enter/exit.
Or you could keep setting the handler in update, but that’s obviously not a good idea…

:wave:

Are you using overlap() or collider()?

this.text.visible = false;

    this.interactive.forEach(function(item){

        var boundsA = this.player.getBounds();

        var boundsB = item.getBounds();

        if(Phaser.Geom.Intersects.RectangleToRectangle(boundsA, boundsB)){
                this.text.visible = true;

}

    },this);

Right now im using this in update, but that is not good idea

How can i know that i walked out of zone?

Here’s one by samme:

I tried that example line by line and that was the problem, as soon you stop moving inside of zone game doesn’t know that im inside.

Try same example and add option to move box with keyboard then game will not detect overlap because velocity is 0 when you stop.

i record video

Hmm, maybe like this then?

1 Like

You are lifesaver! Thank you very much. I tried already same solution like your is,but it was not working thats why i reached forum. After examine my code again with your code example i found i had problem with class inheritance variable that didnt notice until i didnt try your code and that why this was not working!

Thank you very much!!!

I just figured out you should use embedded instead of touching :smile:

1 Like

omg i didnt check this when you replied, Embeded is so powerfull, it saved a couple of code lines and its more precise than custom code.

I basically just walk into zone and text is show, go outside its hide and all that it takes just one if