We are a small indie team of two, developing our dreamed city builder strategy game. We are looking forward to collaborate with community to achieve unique game experience, thus we are eager to collect feedback from our players to improve the final state of the game.

Report RSS DevBlog #4 - AI

Posted by on

Hello everyone and welcome back :)

It's me Lukas and today I will talk about how the AI (Artificial Intelligence) works in Darfall and what we use in the background to drive it.

At the very early stages of the development, the AI for our units was quite simple, like moving to a position, or attacking a target. I wrote this behavior in pure code with my own implementation, but it turned out to be super messy and unreadable quite fast. Even such a simple AI behaviors takes A LOT of code to write.

Later on I tried to research what other tool I could use for our AI. I came across Behavior Designer, the most popular AI asset on the Unity asset store. In the Behavior Designer, you put nodes on a visual graph and depending on how you place and connect your nodes, it will create AI logic you desire.

Simple Tree
Here is a very simple node example, showing how the AI waits for some time, then picks a random position and walks towards it.



You could probably deduct what these nodes do even if I did not explain the logic behind them. This is why having a visual tree such as Behavior Designer helps immensely during the AI development and navigating its different parts.

Woodcutter AI
The following tree shows a small example part of the woodcutter AI. The nodes are evaluated from left to right, where left nodes have the highest priority and always try to execute first.



1. Do we have any resource to carry?
- If yes, carry it to storage
- If not, continue to the next node segment 2.

2. Have we found any resource to gather?
- If yes, move towards it and gather it
- If not, continue to the next segment 3.

3. Wander around aimlessly until the worker faints out from exhaustion :D

Player Unit AI
Here is another example, a full tree that represents the AI behind the player warrior units:



You can see how complex this can get very quickly even with a such visual tool :)
Now you can imagine how hard would it be to write all this AI logic in pure code, without any visual tree representation.

The AI is usually the most challenging feat to handle during any game development. I had to rewrite the entire AI in Darfall for several times already, using different approaches or plugins, such as NodeCanvas.

I'm happy how it turned out and that Behavior Designer trees were a good choice, reducing future bugs, or making it much easier to implement new AI logic like possible boss fighting mechanics.

See you in the next dev blog post!

Martin and Lukas from SquareNite and from beyond the darkness of Darfall.

Check out our Discord -Instagram - Twitter - YouTube - Steam - Official Website.

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: