Posted May 18, 2024 by Menector
#technical #creatures #creatureAI
If we want our creatures to feel interesting, they must be intelligent. An ideal way to make creatures feel realistic is to give them the ability to independently view and act on the environment. In my experience, the best video game creatures were always those that could independently reason about their environment. These truly gave unique and interesting experiences, and each encounter felt like a new experience. I started by taking some inspiration by one of these games' devlogs, Rain World: https://candlesign.github.io/Rain-World-Devlog/Pages/001
Unfortunately I do not have the artistic assets that they did when they started, so we are working from the "inside out": fleshing out the behaviors we want before focusing on the visuals. They started by giving their creatures the ability to move, see, and reason about their environment and then let them go on their own way! In that spirit, I am focusing first on enabling my creatures to move and interact with their environment first. Once they are finding their way, we can start working on survival and evolutionary traits.
First, I had to get familiar with Unreal Engine. I chose UE for this project because I anticipate significant performance improvements will be needed to host this world, and I am fairly familiar with C++. Also, my experience with Unity networking suggests that it would not be an ideal engine for managing a data-intensive MMO such as this. All of this in addition to some of their recent predatory practices with terms and conditions (which I will NOT discuss here!).
One major benefit of Unreal is that it already has the basic functionality I want with respect to creature perception (sight). It took less than a day to have a working setup with a creature that would follow me. However, the difficulty lies in how to track. Most guides treat perception as a one-and-done system where "enemy AI" only has to track the player. In our case, we need them to track multiple nearby creatures. Beyond this, for each creature we must know WHO it is, WHETHER it is in line of sight (currently being viewed), and WHERE it was last seen. In addition, we may want further features, such as tracking potential THREAT. This could enable each creature to decide if/when it is overpowered and should retreat, as well as how to prioritize its targets.
That last point is something far too many games ignore. We want our creatures to have a sense of self preservation! So, we created a short term memory (STM) system. This STM manages what has been seen and decides when to forget old memories. After all, at some point our creatures should move on with their lives and forget about their last encounter! You can see this in action below:
In this case, the creature follows me around the corner to where it last saw me, then forgets and returns to what it was doing. A simple behavior, but a good start. Eventually it needs to search the area if it really wants to find me! Please note that until the basic behaviors are all done, I'll be using default assets. This obviously does not reflect what the game will look like later!
On its own, this is not much different than what most online guides would show you. However, with multiple creatures you can start to see the benefit of this STM:
Notice how creature 1 was chasing me, and creature 2 (when it saw me) started chasing as well. However, when they saw each other, creature 1 decided that 2 was a better target. Meanwhile, creature 2 decided that 1 was too dangerous, and began to run. Both creatures were still aware of me, but had decided that I was not the most important target anymore! (For some context in the video, I set vision to 360 degrees for convenience, green was their limits for noticing me, red was their visual limits of when they'd lose me).
Much work still needs to be done, but this already helps demonstrate the benefits of a sight-based system. As it becomes more developed, creatures will even have ways to identify beyond sight! All in all, this process took about another day, so I can make good progress when I am able to find time at the computer (and away from the baby!). Something else to keep in mind is that aspects of this can eventually be adjusted based on a creatures (knowledge) attribute! Everything from time to forget, delay in decision making, and number of memories can be adjusted. This could mean that low knowledge creatures have a sort of tunnel vision where they focus on one enemy while high knowledge creatures maintain records of many creatures for long periods of time!
As of now, my next focus will be on refining their basic movement and navigation skills. I'd like to find better pathing options for running away as well as approaching targets. Ideally, I want a sort of "pressure" exerted by high threat creatures that results in paths that avoid potential danger. Hope to update on this soon!