Kalia and the Artificial Intelligence


Hello again! Hope you've all had a good weekend so far!

For this week's devlog, I wanted to present and discuss the upcoming AI changes in KatFS. This week has proven quite productive in that department, and thus I'm able to bring many demonstrations that hopefully should be of interest if you're a fellow dev looking for inspiration to write your own AI system, or if you're just a player that has an interest in seeing what goes on under the hood.

Probably just the wind

First, some background on the motivation for the AI overhaul. While simple behaviors such as tracking the player and attacking were enough to set up a prototype (and the early pre-alpha), KatFS has always been planned to include a few light immersive sim elements. The fire mechanics make for its core component, from which many interactions and behaviors can emerge. Volatile slimes that explode, spiders that are frightened by fire, constructs that will overheat and become vulnerable, goblins that are specialized in putting out fires...

Clearly, "track and attack" AI wouldn't suffice.

My initial plan was maybe a bit overambitious - create a modular AI system that could be used for all enemy types in the game. It seemed like a good idea, it would allow AI to be standardized to a degree while still being different from one another. An example that comes to mind is The Elder Scrolls: Oblivion. All the NPCs, animals and monsters in that game had (or at least appeared to have) the same core AI system, with only different variables and tweaks between them.

You're supposed to attack ME, not each other!

This system proved to be insufficient as soon as I had to introduce the AI for the main boss of the demo. At that point I had two choices: either I would try to tear open the (already bulky) modular system to fit in the new behaviors, or I would have to code a dedicated AI for the boss. I opted for the latter, and then I realized how much more straightforward the AI script became when it wasn't split between multiple layers of modules. Therefore, I realized that in order to be able to achieve my goals while keeping my sanity, I would have to give up on the "catch-all modular AI" dream and instead go for a more down to earth approach with specialized AI.

That's the boring, behind-the-scenes part done. Now for the interesting stuff, what's new within the AI? Well, for a starter, I finally decided to generalize the AI targeting behavior. What do I mean by that? Well, the AI can now target other AI, not just the player. Additionally, each AI script can have its own "rules of engagement", allowing for interesting interactions to emerge between monsters (and also serving as an extra avenue for me to present some lore behind them).

Stand back, I'm teaching them a lesson about spacing!

For example - the zombies are interested in only one thing: flesh. They have no reason to attack the skeletons, and will ignore them if possible. The skeletons, on the other hand, are quite skittish, and will attack anything that moves. This creates a scenario where there's an instigator to combat between mobs, rather than them fighting each other just because. Zombies will fight back against their attacker, but even this can be made different for other mobs. For example, slimes might not be able to hurt the skeletons, and thus opt to run away if attacked by them.

Dude, let me go!

Another important addition has been an auxiliary system to make mobs work better as a group. While the zombies are not very smart and will just attempt to pile on you, the skeletons have some semblance of tactical skills left in them, and will attempt to encircle Kalia and close her off. To do this, I have set up a "squad" system that an AI script can make use of as needed. Mobs are assigned to a squad by the level designer, and a dedicated "squad AI" will analyze who's part of it and what are their roles and statuses, and plan accordingly. The individual AIs then can use these plans to control their own moves (or choose to ignore them altogether).

Okay, gather around me

In the GIF above, I demonstrate the logic behind the encirclement behavior by exaggerating the "squad AI" positioning logic. The simple explanation is that skeleton brawlers will attempt to space themselves evenly around their target. The full explanation is that the "squad AI" will provide each of its members with a "suggested position" that they will use if available (otherwise the default behavior takes over). Aditionally, the squad AI has to keep track of who's engaging who, so that if the squad is split up between two targets, the two subgroups will still attempt to encircle their respective targets. Right now there's still no way for squads to pick up new members or merge, but that might also become an important aspect of the system.

The vibes here are all over the place

And this is it for this devlog! The AI improvements are not yet complete, but they will come soon in the next update for the KatFS demo! If you've made it this far, I thank you for your interest! I'm open to questions in the comments to this devlog, if there's something you want to know more about. Toodles!

Get Kalia and The Fire Staff Pre-Alpha

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.