# How do they keep track of the NPCs in Left 4 Dead?

How do they keep track of the NPC zombies in Left 4 Dead?

I am talking about the NPCs that just walk into walls or wander around aimlessly. Even though the players cannot see them, they are there (say inside rooms or behind doors). Let's say there's about 10 or so zombies in a hallway and inside rooms. Does the game keep all of those zombies in a list and iterate through giving them commands? Do they just spawn when the user is within a certain radius or reached a special location?

Say you placed the 4 units (controlled by players) on completely different places throughout the map. Let's assume you aren't being swarmed and then you have not killed any of these aimless NPCs. Would the game be keeping track of 10 x 4 = 40 zombies in total?

Or is my understanding completely off?

The reason I ask is if I were to implement something similar on a mobile device, keeping track of 40 or more NPCs might not be such a great idea.

• I have seen a presentation made by the Valve explaining everything about the zombies in L4D. I can't find it though. – The Communist Duck Feb 16 '11 at 19:31
• @ The Communist Duck - That would be very useful. Please post if you ever find it. The only thing I can find online are game faqs. – f20k Feb 16 '11 at 19:35

You are interested in the paper found here:

AI Systems of Left 4 Dead

• Yes, this is exactly what I am looking for thanks! – f20k Feb 16 '11 at 20:35
• No problem. Lucky for us that devs are kind enough to put up their publications. – ChrisE Feb 17 '11 at 15:32

I haven't read the paper that ChrisE wrote a link to, but from either a conversation I had with a Valve employee or somewhere on their Development Wiki (can't remember which) I remember being informed that they essentially have only a couple of real entities (the AI director); the avatars you see portraying the infected NPC's are just "finger-puppets" to those entities. They did this to keep the number of edict (entity dictionary) entries to a minimum since there are obviously a ton of infected NPC's to keep track of.

The engine's entity dictionary has a fixed size and cannot grow. This means that any game built on this engine which requires a large amount of NPC's--or any entity for that matter--has to make use of such system in order for the engine to function properly and not choke (and ultimately crash) because the entity count is too high.

• Do you happen to know what other kind of entities are there? Would the special infected be entities? I am having trouble understanding "entity" vs "finger-puppet" when I can interact with the infected NPC. – f20k Feb 17 '11 at 17:26
• Specials are entities. Easiest way to determine whats real and whats faked is to watch the console. You can take damage from other players, from specials by name, but when you take damage from commons the console shows you taking damage from "world" (iirc). – Rob N Feb 18 '11 at 6:42
• Yes I see your point. They just crowd around me and do a clawing animation. That is very interesting, thank you. – f20k Feb 18 '11 at 22:32
• Probably the best way to explain how the 'finger-puppet' concept works is by comparing it to a sheep dog. There is one 'controller' (eg: the dog) and a herd (or horde in this case) of 'puppets' (eg: the sheep). The 'puppets' cannot think for themselves, they do only what the controller directs them to do. The puppets are basically an extension of the controller entity but instead of using one single visual element, such as the case with special infected, they use multiple visual elements that are controlled independently. – Cale Feb 28 '12 at 6:27

I can't speak to how the Left 4 Dead implementation works, but I can say how I'd probably do it.

I'd go for something like your second option, track each player and only load NPCs when players move past trigger points. The key in a system like this, is to make the trigger points far enough away from the player that they are unable to associate that walking past this fence post triggers that car to blow up, and shoot a zombie at them.

I would probably have an active NPC collection, which the trigger points either add or remove NPCs from the collection. This allows you to spend CPU/GPU resources on NPCs that players are actually interacting with, but it gives you the flexibility to load NPCs at any time.

Think about a boss who can hear sounds, maybe the boss is loaded at the start of the map and if the player going through the map makes lots of noise (grenades, pipe bombs, etc), the boss will seek out the player and attack out of the blue, instead of waiting till the player reaches the boss arena.