Source SDK

Source SDK

27 ratings
Getting NPC's Moving in Half Life 2 games
By Jim_Partridge
A guide explaining how to get NPC's to move around maps in the Half Life 2 games
   
Award
Favorite
Favorited
Unfavorite
Methods for Moving NPC's in Half Life 2 games
Hey....

For ages I've been trying to work out how to direct, respawning NPC's to move to a particular place on a map. This sounds simple but every method I've tried so far has had problems.
I'm using the npc_template_maker entity by the way...

Last night I cracked it however and wanted to share the pro's and con's of each method I had discovered...

Before I start this a quick word on Info_Nodes in the Half Life 2 games. If your NPC's are not following the instrucitons from the entities below, the number 1 culprit is that they can't find a decent route through the node graph. You can check this out by using the AI_Show_Connect command. This will show the nodegraph in greenlines on the map and you can then spot any breaks.

NPC's don't like slopes. Use steps instead.

Use NPC_Clip texture to create flat surfaces for NPC's if they're struggling with terrain.

Target Path Corner NPC flag
In the NPC variables you'll find the option to specify a path corner that they should move to. This works as a very basic method to move a single spawning NPC to a place on the map, however when attempting to send respawning template npc's (who all have the same name) the AI seems to glitch.

Scripted_Schedule
Used primarily for animations however can be a very powerful way to move NPC's with no questions asked. For respawning NPC's all with the same name, you have to copy the Scripted_Schedule several times, there has to be one for each NPC you're working with.
Just leave all the animation values blank. The NPC will reach the location, try to play the animations, realise there aren't any, and then return to normal AI.

Good to use obviously for animations and for single (not respawning) NPC's. Seems to work best for fast zombies in hl2 if you're working with those. They are stubborn little gits, as are striders...

AI_Goal_Assault
This works fine if you're intention is for the NPC's to move through a map and conquer a particualar point on the map. Once that point has been cleared of enemies however, the assault with then be deleted and so the npc's will no longer follow the directions.
If you want to shut off the npc spawning once a point is conquered then this could work for you. You could send in combine soldiers until they own a spot.

Note that for Combine Soldiers, you don't need to use an AI_Goal_Assault entity. You can send a "beginassault" command directly to the npc_combine_s and it will begin the assault you have specified.

AIscripted_schedule
This is probably the best entity to use for getting your NPC's moving. It keeps AI intact and you can define what should interrupt the behavior (damage/death).
For ages I couldn't get this to work with re-spawning NPC's. Last night I discovered that you must tick the "Search Cyclically" box in order for this to issue orders to re-spawning bad guys.

Here's some other handy hint's on this entity:
1: Use !Activator
Instead of naming a specific NPC in this entity, use the term, "!Activator"
The !Activator is the entity that invoked the schedule.
So basically, in an NPC_template_maker you can use the onspawn output to call the schedule and start it. The !Activator will then always be the npc who just spawned, and they alone will follow the instructions the schedule is dishing out...
Using !Activator basically means that any NPC in your map can use that schedule, not just one specific NPC

hope that makes sense...

2: Use the schedule as its own goal entity
Previously, i was always creating info_targets and using those to indicate the destination of where i wanted my NPC's to move to. Then it occured to me that the NPC's just the name of any entity. It doesn't matter why type. So why not use the schedule itself as the destination marker. This way you can just plonk your schedule in the exact spot you want the NPC's to go to.

Hope this is useful to someone...

Acknowledgements: Marnamai
5 Comments
jaid.exe 11 May, 2022 @ 9:47pm 
cuz for some reason some steam dev decided that people would want to subscribe to every comment section you ever post in.
SunnySideEggs 11 May, 2022 @ 1:06pm 
why did i get notified of this comment 3 years later
Jim_Partridge  [author] 11 May, 2022 @ 2:16am 
Thanks i'll take a look.
SunnySideEggs 23 Oct, 2019 @ 11:33am 
I love you, I've been trying to do this for 2 weeks and this works :cleancake:
ВЛАДИЧКА 25 Nov, 2016 @ 2:41am 
It is possible more in detail about info_target, I viewed maps hl2, but did not understand how to use them.