# How to check overlap of object with any objects?

**URL:** <https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694>\
**Category:** Phaser 3\
**Created:** [October 15, 2020, 6:52pm UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694 "2020-10-15T18:52:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azowarg](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@Azowarg](https://phaser.discourse.group/u/Azowarg)\
**Post date:** [October 15, 2020, 6:52pm UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694/1 "2020-10-15T18:52:17Z")

</div>

Phaser 3.24.1, Arcade physics

Hello there,

I’ve added overlap checking for object player, but i have questions:

```
 this.enemies = this.physics.add.group({
                key: 'enemy',
                repeat: 11,
                setXY: { x: 12, y: 0, stepX: 70 }
            });
  this.physics.add.overlap(this.player, this.enemies, () => {
                console.log('overlap');
            }, null, this);

setInterval(() => {
            this.enemies = this.physics.add.group({
                key: 'enemy',
                repeat: 11,
                setXY: { x: 12, y: 0, stepX: 70 }
            });

  this.physics.add.overlap(this.player, this.enemies, () => {
                console.log('overlap');
            }, null, this);
            }, 5000);

```

This code works only with first wave of enemies.  
Overlap not working for second wave, so I add overlap each new wave of enemies.  
How to fix this?

How to add trigger to check overlap for each object?  
For example - player can shoot. I think - it is not good solution to add overlap listener to each bullet =)

---

<div class="post-metadata">

**Author:** ![seyuup](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@seyuup](https://phaser.discourse.group/u/seyuup)\
**Post date:** [October 15, 2020, 7:17pm UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694/2 "2020-10-15T19:17:19Z")

</div>

Can you post the code that you were using before? Are you creating separate groups for each wave?

---

<div class="post-metadata">

**Author:** ![Azowarg](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@Azowarg](https://phaser.discourse.group/u/Azowarg)\
**Post date:** [October 15, 2020, 7:33pm UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694/3 "2020-10-15T19:33:48Z")

</div>

I attached file with this scene. Could you take a look please?

[scene.js](https://phaser.discourse.group/uploads/short-url/cQTPYGF47Jr3Uxdi0VRJYEeZZz5.js) (2.8 KB)

---

<div class="post-metadata">

**Author:** ![seyuup](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@seyuup](https://phaser.discourse.group/u/seyuup)\
**Post date:** [October 15, 2020, 7:49pm UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694/4 "2020-10-15T19:49:44Z")

</div>

Phaser 3 Scenes appear to have timer functionality that can work as you are trying to do:

> **[Phaser 3 API Documentation - Class: Clock](https://photonstorm.github.io/phaser3-docs/Phaser.Time.Clock.html#addEvent__anchor)**

  

> **[Timer - Notes of Phaser 3](https://rexrainbow.github.io/phaser3-rex-notes/docs/site/timer/)**

Instead of creating a new Group every interval, can you just create a new batch of images (11 in your case) and add them to the already existing Group?

**Edit**  
You may eventually need to get into Object Pooling so you aren’t creating too many enemies (if that is a concern for you).

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [October 16, 2020, 2:31am UTC](https://phaser.discourse.group/t/how-to-check-overlap-of-object-with-any-objects/7694/5 "2020-10-16T02:31:19Z")

</div>

Remove the `setInterval(…)`.

That’s creating a new group each time but overwriting the reference (`this.enemies`).

Set up a timer event and use `this.enemies.createMultiple(…)` instead.
