I am trying to damage player or enemy when they collide.(enemy will be damaged when collided with bullet and player will be damaged when collided with monster)
this.game.physics.arcade.overlap(this.laser.bullets, this.zombies, this.hitEnemy, null, this);
this.game.physics.arcade.overlap(this.player, this.zombies, this.playerdmg, null, this);
}
playerdmg(player,zombies){
player.damage(1); //oneshots
}
hitEnemy(bullets,zombies){
zombies.damage(1); // one shots
console.log(zombies.health) // this is -1
console.log("hit");
bullets.kill();
}
Collision detection works.but i cant damage player or zombies. this is how i set health after creating player:
this.player.health=10;
how do i set zombies health correctly ? because i create them with for loop like this:
this.zombies = this.game.add.group();
this.zombies.enableBody=true;
this.zombies.health = 5;
for (var i = 0; i < 30; i++)
{
var zombie = this.zombies.create(this.game.world.randomX, this.game.world.randomY, 'zombie');
let zombieHealthBar = new HealthBar(this.game, zombie, 25, 10, -20, 0, '#FF0000', '#00FF00');
}