# Problems with collision detection

**URL:** <https://phaser.discourse.group/t/problems-with-collision-detection/9968>\
**Category:** Phaser 3\
**Created:** [July 17, 2021, 4:32pm UTC](https://phaser.discourse.group/t/problems-with-collision-detection/9968 "2021-07-17T16:32:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arminimamovic99](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/arminimamovic99/32/5398_2.png) [@arminimamovic99](https://phaser.discourse.group/u/arminimamovic99)\
**Post date:** [July 17, 2021, 4:32pm UTC](https://phaser.discourse.group/t/problems-with-collision-detection/9968/1 "2021-07-17T16:32:03Z")

</div>

Hi, I need to detect collision between two game objects but event when they ‘touch’ each other on screen, the collider callback doesn’t seem to work.  
This is my code:

```javascript
const move1 = setInterval(() => {
      container1.x += 1;
    }, 20);

    const move2 = setInterval(() => {
      container2.x -= 1;
    }, 20);

    this.gameInstance.physics.add.overlap(container1, container2,() => {
      console.log('overlap detected..')
    })
    this.gameInstance.physics.add.collider(container1, container2, () => {
      console.log('COLLISION DETECTED')
    })

```

---

<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:** [July 17, 2021, 4:34pm UTC](https://phaser.discourse.group/t/problems-with-collision-detection/9968/2 "2021-07-17T16:34:56Z")

</div>

👋

Don’t use `setInterval()`. Use the scene `update()` function instead.

Collisions needs velocity to work properly. Don’t move the `x` and `y` of physics game objects. Give them velocity instead.

```javascript
container1.body.setVelocityX(60);

```

---

<div class="post-metadata">

**Author:** ![arminimamovic99](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/arminimamovic99/32/5398_2.png) [@arminimamovic99](https://phaser.discourse.group/u/arminimamovic99)\
**Post date:** [July 19, 2021, 10:14am UTC](https://phaser.discourse.group/t/problems-with-collision-detection/9968/3 "2021-07-19T10:14:40Z")

</div>

Thank you.  
I used the setVelocity, but i need the 2 objects to move towards each other on the X axis, so I have to move their x. With only setVelocityX nothing happens.

---

<div class="post-metadata">

**Author:** ![BlunT76](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/blunt76/32/1454_2.png) [@BlunT76](https://phaser.discourse.group/u/BlunT76)\
**Post date:** [July 19, 2021, 3:30pm UTC](https://phaser.discourse.group/t/problems-with-collision-detection/9968/4 "2021-07-19T15:30:06Z")

</div>

Show your code with velocity
