Hello,
I am not going to give you some code to program your AI but i am going to give you the manner i used in the past for making a little AI.
I used to write on paper the different rules to drive the AI components.
By example, i wrote some things like that to force ennemy(ies) pursuing the hero :
- first, if ennemy(ies) are far away of the player (150 pixels away), ennemy(ies) must not follow nor attack the player
- second, if 2 or more ennemies are closer enough of the hero, only one can follow and attack the player
- and so on…
What is important here is to describe every rules of AI in clear language to be able after to translate them into visual scripting conditions and actions but also in a programming langage.
With this method , you are not dependant of the games engine or informatic language you’ll use to realize your game.
Bye