I have an animation that when my bullet hits enemy, an explosion animation plays. The enemies have a setVelocity(100, 0) however whenever the explosion animation plays, it explodes at the position where the enemy spawned instead of where it was last at. Help appreciated
//enemy hit callback - called in the update of my enemy class constructor
function enemyHitCallback(enemyHit, bulletHit)
{
// Reduce health of enemy
if (bulletHit.active === true && enemyHit.active === true)
{
enemyHit.health = enemyHit.health - 1;
console.log("Enemy hp: ", enemyHit.health);
// Kill enemy if health <= 0
if (enemyHit.health <= 0)
{
var destroyed = [];
this.enemy.setActive(false).setVisible(false);
this.turret.setActive(false).setVisible(false);
this.shadow.setActive(false).setVisible(false);
}
if (destroyed)
{
this.anims.play('kaboom');
}
// Destroy bullet
bulletHit.setActive(false).setVisible(false);
}
}
//explosion pool - called in my create function
this.anims.create({
key: ‘kaboom’,
frames: this.anims.generateFrameNames(‘explosive’, {start: 0, end: 23})
});