Reputation: 70
I'm using Phaser 3
create(){
this.player = this.physics.add.sprite(100, 450, 'player');
this.enemy = this.physics.add.sprite(100, 450, 'enemy');
this.physics.moveToObject(this.enemy, this.player, 100);
}
So far i have this but because i'm using this.physics.add.sprite and not this.physics.add.image it doesn't work.
I specifically need to use this.physics.add.sprite
editted:
enemyFollows () {
this.enemy.x = this.player.body.position.x;
this.enemy.y = this.player.body.position.y;
}
Now using this but need to have it slowly moving to player's body position.
Upvotes: 1
Views: 2287
Reputation: 70
I got it to work.
enemyFollows () {
this.physics.moveToObject(this.enemy, this.player, 100);
}
I didn't put it in the create() function but made a new function for it and called the enemyFollows() in the update()
like this
update() {
this.enemyFollows();
}
Upvotes: 1