Skip to content
KnowledgeCity

Unity Advanced: Interactions and Gameplay

Create a patrol and line-of-sight action for a non-player character in Unity
Preview the first lesson free — get full access to all 8 lessons.
Course: On-Demand
Advanced Provider Ken Geary  8 Lessons ·  59m  in English 

Course Description

In these lessons, you will learn how to code an NPC to react to transition animator clips. We will explore using the imported walk, sneak, and idle motion capture files; and you’ll add line-of-sight actions to the NPC so that it detects the player. You’ll also expand your coding skills to add interactivity for picking up items, player detection, and sending score information to the UI overlay. By the end of these lessons, you will be able to code AI interactions NPCs.

You will create a patrol system that directs the NPC to walk up to randomly coded waypoints, with a line of sight for detecting the player. Once the player is detected, the NPC animator will transition to a sneak animation loop and the Navmesh target will be switched to the player. We’ll show you how to code the player to enter a “freeze” state for several seconds when a pursuing NPC collides with them. Then you’ll code it so that any NPCs that aren’t chasing the player will freeze when collided with, triggering other NPCs in the scene to detect the condition and attempt to “unfreeze” the NPC.

What You'll Learn

  • Code NPC patrol systems that direct an NPC to walk to randomly coded waypoints
  • Create a line of sight for NPCs to detect the player and switch the Navmesh target to the player
  • Implement complete player controls, including a timed "freeze" state when a pursuing NPC collides with the player
  • Build game mechanics for picking up items and sending score information to the UI overlay
  • Set up transition animator clips using imported walk, sneak, and idle motion capture files
  • Create overall game controls including scores and win screens

Key Takeaways

  • The course teaches coding AI interactions for NPCs, including patrol, detect, and chase behavior.
  • When the player is detected, the NPC animator transitions to a sneak animation loop and the Navmesh target switches to the player.
  • The player can be coded to enter a "freeze" state for several seconds when a pursuing NPC collides with them.
  • Non-chasing NPCs freeze when collided with, triggering other NPCs in the scene to detect the condition and attempt to "unfreeze" the NPC.
  • Interactivity covers picking up items, player detection, and sending score information to the UI overlay.

Frequently Asked Questions

What will I be able to do by the end of this course?

By the end of these lessons, you will be able to code AI interactions for NPCs, including a patrol system with line-of-sight player detection, complete player controls, and overall game controls including scores and win screens.

What gameplay mechanics does this course cover?

It covers coding NPC patrol paths, line of sight for player detection, picking up items, sending score information to the UI overlay, a player "freeze" state on NPC collision, and NPCs that detect and attempt to "unfreeze" frozen NPCs.

How does the NPC react when it detects the player?

Once the player is detected, the NPC animator transitions to a sneak animation loop and the Navmesh target is switched to the player so the NPC pursues them.

What skills does this course focus on?

The course focuses on Code Inspection, Collision Detection, and System Status.

How are the NPC animations handled?

You learn to code an NPC to react to transition animator clips using imported walk, sneak, and idle motion capture files.