Hi, I have an enemy tank and turret attached to it. I also have a bullet class and I am using it to shoot bullets from the turret however it is not shooting? My bullet class is working because my player object is inheriting the class so the bullet class is not the issue.
If I change my sprite “this.turret” to “this.enemy”, in my enemyFire function call out, it shoots from my enemy tank instead of the turret.
//sprite callouts - in my Enemy class constructor
this.enemy = this.scene.physics.add.sprite(x, y, ‘player2’, ‘tank1’);
this.turret = this.scene.physics.add.sprite(x, y, ‘player2’, ‘turret’);
//enemyFire function
function enemyFire (enemy, player, time, gameObject)
{
if(enemy.active === false)
{
return;
}
if((time - enemy.lastFired) > 1700)
{
enemy.lastFired = time;
var bullez = enemyBullets.get().setActive(true).setVisible(true);
if (bullez)
{
bullez.fire(enemy, player);
}
}
}
enemyFire(this.turret, player, time, this);
//collision callback
this.scene.physics.world.collide(player, enemyBullets, playerHitCallback, null, this);