A simple example – patrolling robot

Let's look at this example (which we will later implement in Unity). Imagine a patrolling robot that shoots anything that gets near it, but works only during the daytime. A possible BT for this kind of agent is shown in the following diagram:

Let's run this BT, assuming that the target is close and it is not night:

  1. The first node is a Repeat decorator; it does nothing but cycle the BTs, so we can ignore it for now.
  2. The selector starts executing its first child; we go down to the left.
  3. We are now at the first Sequence node; again, we execute the first node. IsNight? returns Failure (because it is not night!). ...

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.