When it’s time to give life to creatures and create AI, there are several options : you can code it by writting scripts, or use tools such as Finites State Machine or Behaviors Tree.
Creating the whole Artificial Intelligence by scripts is great for a developer wich is also the one integrating the AI, wich is my case. However it’s not the ideal solution for complex behaviors , especially if you need flexibility and can also be tricky to maintain / debug.
Second option, use common tools to write AI, like FSM and BT. Nice tools, and both BT and FSM can be mixed. I have the bad habit to reinvent the wheel (wich in my opinion is not that bad if you really want to understand the coding way 🙂 ) , but this time i decided to gave try to some public tools instead of coding my system. Unfortunately, after some tries, i end-up with that conclusion: it can works great (BT can be wonderfull !), but not suitable for my needs. I need the creatures of The Dungeon Kingdom to be smart, very smart. Not just simple “if see player, reach and attack” style behaviors. I also need the creatures’s Artificial Intelligence to be smart, tweakable, and easy add variety to a base one. With those requirements in mind, it can be tricky to handle such an AI with common tools. I then decided to revisit an 8 years ago AI design i have written in c++ for a AAA class game. Of course, i have rewritten all from scratch in c#, and improving it greatly !
So what’s this AI system like ? Basically, it’s a “virtual” brain, and like any real creatures, it is made of elements/features such as sensors (vision, hear noise…probe environment…), memory (in my design, i call them cells. Add to this macro behaviors and controllers and you get the AI system. I won’t enter too much in details here, but the system has been created with flexibility in mind, and fast complexe behaviors creation. Sensors automatically create Cells, wich have automatic values history tracking and others cool features, behaviors and controllers ( a controller is permanent / parallel behavior in this system) has weight, randomness, priority, cooldown and all you can dream to help the brain decide wich behavior to execute. Let’s see how does it look into the editor (here in play mode) :
Brain Tool showing behaviors
Cells, Sensors, Controllers…
You can also notice in the 3D viewport some lines and differents shapes wich are sensors debug informations, like creature’s field of view etc. etc.
This brain setup is basic, but already good enough to create unpredictable behaviour (by the player) .
That’s all for this post, next time i’ll talk a bit about the creature navigation !