overlapphaser-frameworkcollider

Phaser 3 piercing bullet hit multiple times


for a game I try to make bullets that pierce enemies, which itself is kinda easy thanks to the overlap() function. My problem is that the bullets hit the enemies multiple times and kill them instantly in the end.

Is there a way to say "hit/collide only one time per enemy"?

My collision:

this.scene.physics.add.overlap(
     this.scene.enemyGroup, 
     this.scene.playerProjectiles_PierceEnemies, 
     function (enemy, projectile) {
          enemy.health -= projectile.dmg;
          if (enemy.health == 0) {
              enemy.destroy();
          }
     });

Solution

  • You could add a "is_live" attribute to the bullet and upon collision update the attribute to false, and then in your overlap() function only check live bullets.