# Collider fires endless without colliding

**URL:** <https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216>\
**Category:** Phaser 3\
**Created:** [March 31, 2021, 8:22am UTC](https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216 "2021-03-31T08:22:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiroho](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/kiroho/32/5004_2.png) [@Kiroho](https://phaser.discourse.group/u/Kiroho)\
**Post date:** [March 31, 2021, 8:22am UTC](https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216/1 "2021-03-31T08:22:09Z")

</div>

Hi,  
I tried to make a bouncing bullet for a game that should disappear after bouncing 3 times. I gave my bullet a variable with the value of 3 and decreased it in my bullet-platform collider by one.

However, after testing around, I found out that it must have something to do with how I create my ammoGroup class.  
I use a class “ammoGroup” that extends Physics.Arcade.Group to create multiple bullets (Arcade.Sprite objects)  
I found out that, if I create bullets via ammoGroup (via createMultiple), the collider starts firing for each bullet until I shot them at least once.  
After all existing bullets are fired once, everything works normally and the collider fires as intended → only on collision.

I started with Phaser only two weeks ago an have no idea what to do. I would appreciate any kind of advice. 🙂

The project on Github: [GitHub - Kiroho/Game](https://github.com/Kiroho/Game)

My ammoGroup class  
class AmmoGroup extends Phaser.Physics.Arcade.Group {  
constructor(scene) {  
super(scene.physics.world, scene);

```
    }

    fire(x, y, direction) {
        const projectile = this.getFirstDead(false);
        if (projectile) {
            projectile.fire(x, y, direction);
        }
    }

    

    loadAmmo(ammoIndex) {
        this.clear();
        if (ammoIndex == 1) {
            this.classtype = Blaster;
        }
        else if (ammoIndex == 2) {
            this.classtype = BlasterBig;
        }
        else if (ammoIndex == 3) {
            this.classtype = Granade;
        }
        else if (ammoIndex == 4) {
            this.classtype = Granade;
        }
        else if (ammoIndex == 0) {
            this.classtype = Laser;
        }
        this.createMultiple({
            classType: this.classtype,
            frameQuantity: 20,
            active: false,
            visible: false,
            key: ['ballAnim', 'kugel']
        })
    }
}

```

My bullet class

```
class Blaster extends Phaser.Physics.Arcade.Sprite {
    constructor(scene, x, y) {
        super(scene, x, y, 'ballAnim');
        this.dmg = 25;
        this.enemyHit=[];
        
        //Animation in eigene Klasse auslagern
        this.scene.anims.create({
            key: 'wobble',
            frames: this.anims.generateFrameNumbers('ballAnim', { start: 0, end: 1 }),
            frameRate: 10,
            repeat: -1
        });
        this.anims.play('wobble', true);
        
    }

    fire(x, y, direction) {
        this.body.reset(x, y);
        this.body.setGravityY(-3000);
        this.setActive(true);
        this.setVisible(true);
        
        if (direction == "left") {
            this.setVelocityX(WeaponConst.VELOCITY_X_BLASTER * -1);
        }
        else if (direction == "up") {
            this.setVelocityY(WeaponConst.VELOCITY_X_BLASTER * -1);
        }
        else {
            this.setVelocityX(WeaponConst.VELOCITY_X_BLASTER);
            this.setVelocityY(WeaponConst.VELOCITY_Y_BLASTER);
        }
    }

    preUpdate(time, delta) {
        super.preUpdate(time, delta);

        if (!this.scene.cameras.main.worldView.contains(this.x, this.y)) {
            this.enemyHit = [];
            this.setActive(false);
            this.setVisible(false);
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [March 31, 2021, 1:07pm UTC](https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216/2 "2021-03-31T13:07:45Z")

</div>

The collider will only fire when the bullet body is enabled.  
Not sure why this is necessary, but you could put this after createMultiple:

```
    for (let i of this.getChildren()) i.body.enable = false;

```

And then when you fire, set `this.body.enable = true`.

---

<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:** [March 31, 2021, 4:55pm UTC](https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216/3 "2021-03-31T16:55:31Z")

</div>

You need to create bullets with physics bodies disabled. When enabled they can collide, it doesn’t matter if the sprite is `active` or not.

One way is

```js
// AmmoGroup constructor()
super(scene.physics.world, scene, { enable: false });

```

> [@Bullet pools (Phaser 3)](https://phaser.discourse.group/t/bullet-pools-phaser-3/7502):
>
> [Space battle 480x480] A bullet pool is a [sprite pool](https://phaser.discourse.group/t/arcade-sprite-pool/1209) where all the sprites are initially inactive. They are activated when fired and then deactivated when they collide or expire. Bullet pools Bullet pools with extended game object class More examples

---

<div class="post-metadata">

**Author:** ![Kiroho](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/kiroho/32/5004_2.png) [@Kiroho](https://phaser.discourse.group/u/Kiroho)\
**Post date:** [March 31, 2021, 6:11pm UTC](https://phaser.discourse.group/t/collider-fires-endless-without-colliding/9216/4 "2021-03-31T18:11:21Z")

</div>

Disabling the body worked, thank you.

In the meantime I found the checkCollision function, which worked too, when I set checkCollision.none = true when creating my bullets and = false when firing.  
However, it felt like kind of a dirty solution.
