O'Reilly logo

Creating E-Learning Games with Unity by David Horachek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a collection of NPC conditions and responses

To specialize how the NPC will respond, we need to write specific conditions and response classes and then populate the DecisionMgr for the NPC by placing these components in the editor. To prove this, let's develop a test case for an NPC that will perform the following logic:

  1. Patrol on a curve, facing forward.
  2. When the NPC gets close enough to the player, stop and face the player.
  3. When the NPC is far enough away from the player, follow the path and face forward.

To implement this logic, we will need two conditions and one response.

Implementing the condition_closerThanThresh script

Let's create a condition to check if the NPC is close enough to the player. This will be used by the npcDecisionMgr ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required