Search the Blog

Showing posts with label Tree. Show all posts
Showing posts with label Tree. Show all posts

Thursday, September 25, 2014

Deciding which Behavior to use

Have you ever been to a restaurant, and ordered the soup instead of the salad, and wonder why you didn't get the salad instead? What made you choose the boiling liquid over the frozen vegetables? Most of our choices we make each day has to deal with certain conditions and what steps are needed to make those choices. For example, if it was a cold December day outside, maybe you would prefer to soup.

Relating this to video gaming, each AI character follows a tree that helps it determine what needs to be done in order to fulfill its goal. Say we wanted to drive to a store, and pick up some milk. What steps are needed in order to make it to the store? Refer to the following graphic:

Behavior Tree


We start with a selector node that first determines what method we will be doing to get to the store: in this case taking a car or a bike. Our AI will try to use the first option, which is usually the "best" option, unless we randomly choose a method to use. The arrow denotes our sequence node that shows the steps in order for our method to be completed. If all of the steps in a sequence node can be completed, then that sequence succeeds and so does our method.


In our example, our character would first have to open the door to the car. This sounds like an easy task, but what if the car is locked? What if the door is jammed? What if the door is blocked and we can't get to the door itself? An AI character would have to consider potentially every possibility when completing simple tasks. If at any time a step in our sequential node fails, we look back at our selector node for a new path to take.

Looks like we might be taking the bike...