I implemented a swarming behavior today for zombies! They now actively surround targets. If you’re not careful then you’ll end up in the middle of a ravenous horde. You can actually see this happen to several survivors here.
The zombies ignore me so just pay attention to the yellow S’s in game or the yellow squares on the minimap. This is a natural result of how their pathfinding works so its still very performance friendly as there’s no need for flanking calculations or other frame devouring non-sense.
Previously, they would just form a nice and orderly line due to how their pathfinding worked. It’s like they’re patiently waiting for their turn to get a bite. You could sit their for a million turns and those zombies would never move. It just looked wrong and doesn’t seem very zombie like to me. They’re stupid, sure, but they’re also hungry! In media zombies will usually bunch up together in tightly crowded packs or even climb over one another. They never just patiently form a orderly que when fresh brains are present.
This is happening due to how the zombies move. They path by searching their neighboring tiles to find which one is closest to their target. Then they move to it! That’s literally it. They ignore walls and other movement blocking terrain when analyzing these neighbors. However, if said tile is occupied by a fellow zombie then they don’t move. That’s where the problem came from! I shouldn’t really call this pathfinding since there’s no real thinking involved but I don’t know what other term to use.
I had to give them a form of pathfinding that was not only believably stupid but also capable of somewhat trailing a target. It also had to be performance friendly since there’s potentially hundreds if not thousands of zombies active at once depending on the map size. If you look at this example again and look in the corner you’ll notice a counter displaying how many zeds are present. It would of been easier to just give them astar or dij-whateverthefuck but then they would of been too smart.
The way I made this possible is actually pretty simple. If the tile a zombie wants to move to is occupied by another zombie they will choose a new random neighbor and move to it instead of waiting in line like gentlemen. This clears up traffic jams which enables the swarming behavior as a result.