itch.io is community of indie game creators and players

Devlogs

Behavior Tree Blogpost

FNAF: The Mangle
A browser game made in HTML5

For my final project in AI for Games, a class run by Alexandre Tolstenko here at Champlain College, I chose to work on a Five Nights at Freddy’s fangame to display the AI technique of Behavior Trees. I worked with Steven Bruns on our prototype, and I feel that it properly shows off plenty of different behaviors, all being powered by our custom tree.

Behavior trees are a method of agent control that, unlike finite state machines, is task-based. To do this, behavior trees are made up of two different types of nodes. How each type of node works is explained in great detail in “A survey of Behavior Trees in Robotics and AI” by Matteo Iovino, but the gist of it splits it between control nodes and leaves. Control nodes, such as sequence and selector, handle the utilities of the tree. For example, sequence nodes make sure multiple actions play out in the correct order. The other type of nodes, leaf nodes, are used to allow actions to play out. In our implementation, condition nodes and action nodes are the leaves, and they make decisions and run functions respectively. As stated in “Introduction to BTs” on BehaviorTree.dev, each node has three potential states. These states are success, running, and failure. Success is returned when a node is completed. For example, a sequence node returns success when all of its children leaf nodes return success. Running is returned simply when the node is still in progress. Lastly, failure is returned when a node fails to complete its task. While our implementation utilizes 4 total node types (Selector, Sequence, Action, and Condition), there are many more possible node types, as mentioned in “Behavior trees for AI: How They Work” on GameDeveloper.com. Other possible node types that I did not need to use, but could have, were inverter nodes, repeater nodes, and repeat-until-failure nodes. These nodes are referred to as decorator nodes. 

Behavior trees are extremely versatile, and can be used for a wide variety of different game genres. One extremely common genre of game that uses behavior trees are first-person shooters. Halo 2 (The Master Chief Collection Version) was an example of using behavior trees; their AI had dozens of different behaviors, including sequences for engaging, berserk, searching, self-preservation, retreat, ambush, idle, and much more, according to Microsoft Learn’s article “Halo 2 AI Behavior List”. Additionally, MOBAs sometimes use behavior trees, especially for agents such as minions that have simple behaviors that need an easily understandable structure for developers and players alike. Lastly, simulation games such as Sid Meier’s Civilization utilize behavior trees for the NPC soldiers and townspeople who players manage but cannot control directly. 

As far as platforms go, games on virtually any modern platform can be found that use a behavior tree for their AI. PC, console, and mobile can all easily provide enough computational power for many simultaneous, complex behavior trees. More interestingly, behavior trees are used outside of game AI. For example, behavior trees are commonly found in robotics. Robots are not much different from virtual AI agents; they need instructions and tasks to do, as well as control structures for utility (sequences and selections). Thus, behavior trees can commonly be found being used for UAVs (Unmanned Aerial Vehicles), complex robots, and multi-robot systems. This AI technique is used for much more than just games, and has become a key role in the future of robotics. 

Our implementation of behavior trees is just a small look and prototype into the many functions that can be kept together with the backbone of this technique. Mangle’s AI is able to make decisions on where to move based on randomization and conditions of its environment, attack power generators to drain player resources, and attack players from 3 different directions (two doors and a back vent that is invisible to cameras). I am very proud of what Steven and I managed to pull together on this project, and writing a custom behavior tree was an important experience in becoming a better programmer.   

Works Cited

BehaviorTree. “Introduction to BTs.” BehaviorTree.Dev, https://www.behaviortree.dev/docs/learn-the-basics/bt_basics/. Accessed 7 December 2025.

Iovino, Matteo. “A survey of Behavior Trees in robotics and AI.” ScienceDirect, 12 April 2022, https://www.sciencedirect.com/science/article/pii/S0921889022000513. Accessed 4 December 2025.

Microsoft. “Halo 2 AI Behavior List.” Microsoft Learn, December 2022, https://learn.microsoft.com/en-us/halo-master-chief-collection/h2/ai/aibehaviorlist. Accessed 7 December 2025.

Simpson, Chris. “Behavior trees for AI: How they work.” Game Developer, 17 July 2014, https://www.gamedeveloper.com/programming/behavior-trees-for-ai-how-they-work. Accessed 4 December 2025.

Files

  • MangleFinal.zip 38 MB
    12 days ago
Leave a comment