# Collision test "pushes" object - is this a bug or what?

**URL:** <https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591>\
**Category:** Phaser 3\
**Created:** [May 14, 2021, 2:24pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591 "2021-05-14T14:24:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [May 14, 2021, 2:24pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/1 "2021-05-14T14:24:18Z")

</div>

Hi!

I have been around for a little while and I think I never mentioned that I am a game coder coming from ActionScript and Vanilla. After a long time rusting the joints I am back to the game (no pun intended). I am starting with Phaser 3 and am doing some tests myself of how to do basic things before to jump over a project that an old client ordered to me.

Anyway, this morning I was playing with collision tests when suddenly I bumped (no pun intended again!) to this funny behavior. I really would like to know if this a bug or purposeful. I realized that in a particular situation if you try to detect the collision between an object moving towards a stopped one, when they collide the moving object will **push** the stopped object. The funniest part is that it only will happen if both objects has their hit areas set to circle. Better explaining, if you leave it as default (square) it won’t happen. In fact if at least one of the two objects has its area as square it won’t happen. That’s why it has the appearance of a bug to me.

Also being experienced with several other languages it really sounds odd to me that an event function that supposedly should **only make a test** causes a **behavior change**. From my perspective a test should produce only a true/false result but in any circumstance change things (it should be left to the coder to decide what to do depending on the result).

Here it goes the code to reproduce the behavior:

```
var Moving;
var Stopped;

class Foo extends Phaser.Scene
{
    constructor ()
    {
        super();
    }

    create ()
    {
        Stopped = this.physics.add.sprite(800, 300,"");
        Stopped.setCircle(18);
        
        Moving = this.physics.add.sprite(500, 300, "");
        Moving.setCircle(18)
     
        this.physics.add.collider(Moving, Stopped, function (Moving, Stopped) {
        });
    }
    
    update () {
        Moving.x += 5;
    }
    
}

const config = {
    type: Phaser.AUTO,
    parent: "Foo",
    width: 1024,
    height: 768,
    pixelArt: true,
    backgroundColor: 0xffffff,
    physics: {
        default: "arcade",
        arcade: {
            debug: true
        }        
    },
    scene: [Foo]
};

const game = new Phaser.Game(config);

```

😆

---

<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:** [May 14, 2021, 5:51pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/2 "2021-05-14T17:51:09Z")

</div>

`collide()` etc. are not test functions. They resolve collisions by separating bodies, possibly accelerating them, and set collision flags on the bodies.

---

<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:** [May 14, 2021, 5:54pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/3 "2021-05-14T17:54:43Z")

</div>

> [@YanKleber](#):
>
> ```javascript
> update () {
> Moving.x += 5;
> }
> 
> ```

You should be setting velocity instead:

```js
Moving = this.physics.add.sprite(500, 300, "");
Moving.setVelocityX(300);

```

---

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [May 14, 2021, 6:16pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/4 "2021-05-14T18:16:53Z")

</div>

Hey **Samme** this is a very valuable information! Thanks!

I have found [this](https://www.thepolyglotdeveloper.com/2020/08/handle-collisions-between-sprites-phaser-arcade-physics/) tutorial teaching how to detect collision that put it this way, but as per what you said this is NOT the correct way of doing it. Ugh!

Could you point me some example of code where I can learn how to check simple collision detection between two objects? I am so sorry for keep asking things that seems to be obvious, but I have experienced a lot of difficulty of learning directly from Phaser documentation because the lack of code sample…

Thanks!

_PS: I mean, I checked this your suggested change and it worked PERFECTLY for the purposes, but I am puzzled that I had the impression that maybe you mentioned that this is not the right way?_

---

<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:** [May 14, 2021, 6:43pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/5 "2021-05-14T18:43:21Z")

</div>

> [@YanKleber](#):
>
> I have found [this](https://www.thepolyglotdeveloper.com/2020/08/handle-collisions-between-sprites-phaser-arcade-physics/) tutorial teaching how to detect collision that put it this way, but as per what you said this is NOT the correct way of doing it.

[overlap()](http://phaser.io/examples/v3/view/physics/arcade/overlap-collider) is really intended for that case.

The first game tutorial ([Part 6](https://phaser.io/tutorials/making-your-first-phaser-3-game/part6), [Part 8](https://phaser.io/tutorials/making-your-first-phaser-3-game/part8)) covers some of this.

---

<div class="post-metadata">

**Author:** ![YanKleber](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/yankleber/32/5152_2.png) [@YanKleber](https://phaser.discourse.group/u/YanKleber)\
**Post date:** [May 15, 2021, 3:46pm UTC](https://phaser.discourse.group/t/collision-test-pushes-object-is-this-a-bug-or-what/9591/6 "2021-05-15T15:46:31Z")

</div>

Thanks, **Samme** , overlap did the trick to me!
