Book Image

Source SDK Game Development Essentials

By : Brett Joseph Bernier
Book Image

Source SDK Game Development Essentials

By: Brett Joseph Bernier

Overview of this book

Table of Contents (18 chapters)
Source SDK Game Development Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Making NPCs walk


NPC movement and reactions are governed by a set of rules known as Artificial Intelligence or AI. A NPC will walk, run, shoot, or find cover based on a multitude of external stimuli. Each NPC has different AI associated with it.

You could place a generic NPC in your map to add some more immersion, yet without scripts, they won't do too much. As an example, combine soldiers and headcrabs will attack if they see you, but citizens will look at you and acknowledge your presence. These are just default behaviors, but thankfully, we don't have to fully rely on plain NPC AI. We can create scripts to get the NPCs to walk, talk more, and interact with the world. Making NPCs walk is quite easy. The path_corners entity can be used as navigation points for NPCs. There are two main ways to get an NPC to follow a path: with spawn activity and with an aiscripted_schedule.

Simple NPC movement

NPCs can be told to follow a set of path_corners, similar to a train, when they spawn. This is useful...