For my final project in my Advanced AI class, I decided to recreate my own version of the Batman Arkham games guard AI utilizing behavior trees, a topic I haven’t explored before.
First thing I did was find a Unity framework for behavior trees, and with the help of a youtube tutorial created by Mina Pêcheux, I was able to grasp the core concepts of behavior trees and hit the ground running with the project. Thanks to that video (https://youtu.be/aR6wt5BlE-E), I have a behavior tree namespace ready to go, with Node, Tree, Sequence and Selector classes ready to be utilized.
Now for some specifics: In the Arkham games, depending on how the player interacts with the guards, their behavior changes. For instance, if you get spotted by a single guard, every guard’s heart rate rises, changing their animations from casual strolls to a cautious walk. They draw their guns, and even start moving in groups. Of course, it’s also possible to take out every guard without a single one noticing anything’s wrong.
To achieve mechanics similar to this, I attached a fear mechanic to the guards. Depending on each guard’s fear value, they prioritize different actions. Guards with 0-32% fear simply just patrol their respective paths, 33-65% fear causes them to seek out light, 66%-100% fear makes them find another guard to follow. But in the event that there’s no light nearby and there’s no other conscious guards to follow, they fall back to their usual patrol.
Below is a demonstration of the search for light behavior. I used an influence map as a way to give the guards information on where light is and isn't, shown by the green circles. The guard simply scans its range (the white wire sphere) for every cell in the influence map grid nearby and sets its destination to the closest one with any light at all.
The follow guard state behaves similarly, but instead of scanning influence map cells it simply scans for other guards. Notice how the guard turns from green (patrol state) to yellow (seek light state), and finally red (seek guard state).
This is what the final behavior tree looks like. I have it ordered such that checking for nearby guards takes priority when conditions are met, followed by searching for nearby light, and falling back to patrol if necessary.
Additionally, I added an unconscious state that instantly raises every guard’s minimum fear by 10%, but only when a conscious guard discovers the unconscious guard by walking into its radius. When they wake up, the minimum fear gets reverted.
Here's it all in action:
Comments