Im making a game where I need the enemy to spot the player once in a certain range, and then start chasing the player. I cant find anything anywhere at all that would help with how to make sprites chase each other
Im using Kaboom.js, javascript only (no html), on replit.com
Here is my code so far but it does not work because to my knowledge Kaboom.js does not have a way to get only the x position of a sprite
export default function run(speed = 250, dir = -1) {
return {
id: "run",
require: [ "pos", "area", ],
add() {
if (player.pos > this.pos) {
dir = -dir
this.play("runRight")
} else if (player.posx < this.posx) {
dir = -dir
this.play("runLeft")
}
},
update() {
this.move(speed * dir, 0)
},
}
}