Adding patrolling enemy AI to a platformer tutorial.

Article by Richard Davey. Posted on 29th Apr 2016.   @phaser_


From the Kumansenu blog: "Last blog, I detailed how the bullets were implemented on A Modest Platformer; today, I will be talking about the enemy patrol AI. In the demo, Slimes patrol on platforms without falling over the edges. They also change direction when bumping into other Slimes.

We also moved all the collision logic which was previously in the global update function into the object’s own update function. It still works the same way, as each Sprite’s update function is called each time the global update function executes.

We’re still using Phaser’s built in collision detection via game.physics.arcade.collide, but with the addition of an anonymous function callback wherein we define how the each object (slime or platform) would react when a collision takes place.

Each time a collision between a Slime and a Platform takes place, we perform an ‘edge check’ to determine if the Slime is about to fall off. We do this by checking the Slime’s position against the position and dimensions of the Platform it is currently colliding with; if it exceeds the left-most or right-most point of the Platform, we reverse the Slime’s direction and update its animation cycle."

Read More