How do I make a Patrol+Chase & Attack Enemy on a Platformer?

I believe I can figure out how to make a patrol+chase type enemy, because there are older posts about it. But I’m wondering how can I do that in a platformer shooter where I expect enemies to act as players…

Example: mid patrol an enemy spots the player, so he leaves his position to chase + shoot him, and by doing that, he will have to jump on top of platforms, go through jump-tru platforms or anything like it.

Hi - The logic can get quite complicated. There are quite a few threads on enemy ai in a platformer - some of them don’t contain those specific words and don’t come up in the search
you will probably need to put everything related to the enemy under a ‘repeat for each’
use custom points (like these 1,2,3,4) and raycasting and distance between object checks and x and y checks


see the picture - this is how complicated it can get.
the player is above the enemy on another level.
the enemy needs to find a ladder and go up safely
player.Y()<enemyY()-100
and so the enemy raycasts left and right to find the nearest ladder
he identifies the nearest ladder and movement variable is switched to run right.
when point 2 is NOT inside platform enemy has to decide whether to jump.
the pit contains a hazard that is longer than the enemy can jump.
point 2 is inside the hazard and the width of the hazard object is longer than the enemies jump distance and so he raycasts to find a platform that is higher than the one he is on but within his jump range - if it is he jumps right.
having landed on that small platform…
you see how complicated this is getting!
…he needs to successfully jump to the ladder
and so when point 2 is NOT inside platform - he needs to jump to the ladder. You see here that really there needs to be raycasts at a few different angles to check for hazards and decide whether to jump or fall.
ladder logic is also quite tricky.
There needs to be quite a lot of trial and error

1 Like