I have a function that holds the properties of my enemy tank. However, I want the turret to stay on the tank which requires it to be in update but it doesn’t seem to stick to the tank. Is there a way to call update within the function. Here is my code:
enemyPlayer = function (game, player, x, y, bullets) {
//console.log(index);
var x = Phaser.Math.RND.between(0, 800);
var y = Phaser.Math.RND.between(0, 600);
this.game = game;
//this.tank.name = index.toString();
this.health = 3;
this.player = player;
this.bullets = bullets;
this.fireRate = 1000;
this.nextFire = 0;
this.alive = true;
this.tank = this.physics.add.sprite(x, y, 'enemy', 'tank1').setOrigin(0.5, 0.5);
this.turret = this.physics.add.sprite(x, y, 'enemy', 'turret').setOrigin(0.3, 0.5);
/*this.turret.x = this.tank.x;
this.turret.y = this.tank.y;*/
this.tank.body.immovable = false;
this.turret.body.immovable = false;
this.tank.body.collideWorldBounds = true;
this.turret.body.collideWorldBounds = true;
this.tank.body.bounce.setTo(1, 1);
this.physics.velocityFromRotation(this.tank.rotation, 100, this.tank.body.velocity);
this.physics.velocityFromRotation(this.tank.rotation, 100, this.turret.body.velocity);
};
The 2 lines I have commented above are required to be in update otherwise the turret just sticks with the boundaries.