Design the Enemy Behavior

Now, it is time to design the enemy, behavior. Before writing a single line of code, we need to design the enemy behavior:

This is our draft. The tree describes the following behavior:

  1. If it is night, the enemy is deactivated.
  2. If the target is very close, then the enemy shoots at the target.
  3. If the target is a bit further away, the enemy chases the target.
  4. Otherwise, the enemy just wanders around.

There are two important things to note:

  • First, the two IsTargetClose nodes differ in the value we consider close. In particular, we want to shoot the target only if we are really close to the target; otherwise, we just ...

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.