Behavior Trees

In a previous chapter, we saw a basic but effective way to implement and manage character states and behaviors: Finite State Machines (FSMs). FSMs are simple to implement and very intuitive, but they have a fatal flaw: it is very hard to make them scale once states and transitions start getting numerous. For example, imagine a character that behaves differently depending on the amount of health and mana it has (high, medium, and low); we have a state when both health and mana are high, one in which, health is medium and, mana high, one in which they are both medium, and so on. In total, we have nine states just for that. If we add other conditions (such as player proximity, time of day, equipment, player’s score, or whatever ...

Get Unity Artificial Intelligence Programming - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.