Is this not expensive to use?

I realize that I can put physics.add.overlap() in create() and it can work just fine. I am working on a multiplayer online game and what I have right now seems to work just fine, I’m not experiencing any server lag.

Just so I understand better, is it fine for me to run physics.add.overlap() within a function that runs many times per second? Basically like putting it in update(). Is this not an expensive thing that I am doing? That’s all that I am looking to make sure of, thank you.

hi,

i’m using the “collisionstart” and “collisionactive” events from matter.
If u use matter, try this approche:
Inside create method:

        // collision checks
        this.matter.world.on("collisionstart", this.collisionDetection );
        this.matter.world.on("collisionactive", this.collisionDetection );

and the collisiondetection itself:

collisionDetection( event, bodyA, bodyB ){
        event.pairs.forEach( pair => {
//magic
});
)

this should be ok, phaser is calling your function only if a event exists to check :slight_smile:

PS:
see this example for other solution with overlap:

You should either use physics.add.overlap() in create() or physics.overlap() in update().

Never put physics.add.overlap() in update().

1 Like

physics.overlap() in update() works absolutely perfect for my situation. Thank you for the explanation, Samme.