Book Image

Mastering Unity Scripting

By : Alan Thorn
Book Image

Mastering Unity Scripting

By: Alan Thorn

Overview of this book

Table of Contents (17 chapters)
Mastering Unity Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Starting an NPC agent


Now, let's create an AI agent for the level, something that can interact with the player. First, the agent needs a physical mesh representation in the scene. For this, I used the Constructor mesh, which is part of the Unity Character Controllers package imported earlier. Drag-and-drop this from the Project panel into the scene and then remove any animator component that might be created, as shown in the following screenshot. The animations will be important, but a custom-made animator controller will be created later.

Adding a constructor mesh for the enemy character

Tip

Remember that we're not using the third-person controller prefab; it's just the constructor mesh alone.

Next, add a NavMeshAgent component to the object by navigating to Component | Navigation | Nav Mesh Agent. This allows the object to work with the navigation mesh, and it is able to find and travel paths when instructed. Set both the Radius and Height values of the component to match the dimensions of...