BATTLEJUICE ALCHEMIST DEVLOG:
Enemies' Idle Behaviour
Hey everyone! I thought I'd try out a written devlog post as vdapps suggested. It is basically the script of my latest video with a few pictures for those of you who prefer it in this format. For those who like to watch the video, you can watch it on YouTube:
click GIF to watch on YouTube ↑
So what is it all about? I made a stupidly over-engineered need-driven behaviour system for the enemies' idle behaviour in BattleJuice Alchemist. They now waddle around looking for water, food, rest and cover. They learn which of their needs are hard to fulfill and remember that when making their decisions which strategy to follow.Let’s begin with the enemies’ AI behaviour as it was in BattleJuice Alchemist before I started working on the overhaul.
In Unreal Engine you can use behaviour trees to control AI behaviour. The behaviour for my enemies while not fighting the player was quite simple: If the enemy was close to the player and not sleeping and could not see the player, it was idle. In this case the enemy first walked back to its spawning location, which we could call its home. Back at home, it walked around randomly or went to sleep, if it was night time that is.
A funny thing is that enemies waddled around aimlessly before the overhaul and that the finished AI waddles around in a quite similar fashion, but let’s not talk about that and start designing our super sophisticated AI and see where it takes us. The first thing I did was to add a system of needs the enemies can act on. I decided to have four needs: Food, Water, Rest and Cover. I wanted to be able to monitor an enemy’s needs at any time, so I added them to their UI.
If the bar is full means that the need is completely fulfilled. As these values are not crucial for the player to know, I might make it optional to show them or not. But we will leave them on for now.
The value for Food needs to decrease over time. When the enemy is sleeping, Food diminishes slower than when it is awake. It is the same with Water, but for Water I even took rain and fog into consideration. I mean, if the weather is damp, it is not necessary to drink that much, right? I hope that makes any sense. There is a quite elaborate weather system in BattleJuice Alchemist, that I simply pulled the values from. The need for Rest is more simple than for Food or Water. Enemies get tired when awake and even more tired when moving around and doing things. Cover is maybe the most complex value. I thought about having a need for social interaction, but decided to boil that down and integrate it into the Cover value: Enemies want to be close to each other, because they provide each other Cover. That is when they don’t all fall asleep at the same time. I took inspiration from Half-Life’s Houndeyes here. Do you remember those three-legged doggies? They spawn in groups and when the pack goes to sleep, the leader stands on its back food and watches over the others. In BattleJuice Alchemist there is no pack leader, but the last enemy nearby does not go to sleep, when all others around it are sleeping, so it can provide them Cover. Other sources of Cover are trees and buildings for example, but also fog or even Water, if the enemy is amphibian.
This brings us to another point: After the needs were in place I added characteristics to the different enemy types.
Enemies could now be amphibian or nocturnal or loners, all of which influences their behaviour. Now that all needs were implemented and also diminishing correctly, I could have the enemies act towards replenishing them. So let’s take a look at what the new behaviour tree looks like.
If the enemy is not sleeping and not in a fight and cannot see the player, it stops looking at the player and then starts acting towards fulfilling its needs. If there is no need to act on, the enemy starts sleeping or walks home.
If Rest is the most urgent need, the enemy goes to sleep, but only if there is enough Cover.
If the enemy is thirsty, it starts looking for a source of Water and drinks there, if it is hungry, it searches for an area with edible plants.
If the most urgent need is Cover, the enemy simply walks home.The idea behind that is that all the enemies meet at the home location and provide each other Cover there.
Okay, now we already have some pretty cool behaviour, but I wanted to go a bit further. I made a variable called “Wellbeing”, which is calculated as the average of all needs.
The enemy only starts acting towards the most urgent need, if its Wellbeing is low. It then decides on a strategy how to increase its Wellbeing. The main factor is simply, which of the values for Food, Water, Rest or Cover is the lowest. But I also made a simple system, that makes the enemy AI a bit smarter. The AI evaluates the strategies it used to fulfill its needs. For example, if it could not find Food when hungry, it gets biased towards choosing to search Water instead of Food, even its urge for Food is more pressing than its thirst. Put simply, the AI learned that food is hard to come by where it lives. So the creature focusses on the problems it knows it can fix to increase its overall Wellbeing. You could call that a very simple form of memory or learning.
Now that we have super smart enemies, we can hook up their brain to our other systems. For example, Wellbeing is checked, when the player approaches.
If the enemy has a low Wellbeing, it acts more aggressively. Also, Wellbeing influences the physical fitness of an enemy, which means this enemy does more or less damage. As a finishing touch I added the behaviour that enemies check out items that are lying on the ground. Some items replenish a need value, but checking out items also has a nice side effect: it makes the enemies more likely to interact with the player, because the player is very likely to check out items on the ground, too.
So what does this all lead to? We now have an AI that makes enemies waddle around following their needs, which essentially does not look so much different from what they were doing before. But I really enjoy watching them and it makes me happy to know that they themselves now know what they want. As I said, I think what I made here is totally over-complex for an action RPG. But I hope some of you appreciate it in one way or the other.
If you watched the video, you may realise, that this text was really almost exactly the script for the video. Let me know if you think it is really nice to have this in written form or if it is unnecessary. Another thing I'd love to hear your feedback on is whether you think I should have the enemies' needs hidden on the UI as a default. I have the feeling that they are simply of too little relevance, even though I personally like seeing them. Playtesters have had trouble understanding my game as it is, so more clutter is something I think I can't afford. I'm looking forward to hear what you think.
Thanks for reading!
(As a side note, I added a list of links to written devlog posts to my initial post)