I’m trying to make a simple enemy AI where the enemy (animated sprite) moves side to side on the ground but gets faster over time, capping at a max speed .
I’ve followed the official “get started with your first game” tutorial for the platformer and I’m stuck on how to make my enemy move on its own (without player input).
Thanks for the logic samme! That should be able to do it.
A few questions, would I put this code inside the update () or the create()?
Also, how can I get an animation to play on the enemy while it moves? I am currently using the following method to give the enemy animations. I need them to play whenever the enemy moves though:
Mine doesn’t prevent the enemy from stopping, but if you want that you can do
if (enemy.x < LEFT && enemy.body.velocity.x <= 0) {
enemy.setVelocityX(speed); // etc.
} else if (enemy.x > RIGHT && enemy.body.velocity.x >= 0) {
enemy.setVelocityX(-speed); // etc.
}