I want to create a horde of pathfinding zombies. I tried using pathfinding service and tutorials like this one:
Roblox - Zombie Advanced AI Tutorial (Pathfinding, Custom Animations, Raycasting) - YouTube
Just want to clarify that my code is similar to the code in this video but modified (not identical).
Here a video similar to what I am trying to accomplish:
Roblox Zombie AI stuff (Randomized pathing, avoidance, sight checking) - YouTube
So basically how it works is it creates a path, checks if the path is completely clear of obstacles (straight line) and if yes then pathfinding will not be used and the humanoid will just be moved to the target position. If no, pathfinding will be activated and the NPC will follow the waypoints. It works perfectly fine with one or two zombies.
However, it doesn’t seem to work smoothly with a large number of zombies.
There are problems with my script that I am confused on how to fix.
-
Zombies keep thinking each other as obstacles, and so when the zombie can walk to the player in a straight line, it doesn’t and activates pathfinding, trying to find a way towards me as if the other zombies around it are not moving. I’m using raycast to detect if the zombie can run from a straight line to the player.
Attempted Solution #1: I tried adding aPathfindingModifier
every part of the zombie and setting thePassThrough
property to true, however it doesn’t do anything and I was told that the pathfinding service will think of itself as an obstacle (or something like that).
Attempted Solution #2: I tried making it so that the raycasts will exclude the every zombies’ descendant parts, so the raycast won’t detect them. It worked, but it I could either make them not collide, which would make them all group into one giant blob and it looks horrible, or make them collide and it gets extremely laggy. I need to get them to spread out without causing problems. -
Lag. Creating too many zombies will result in massive amounts of lag. Like I said before, it seems to get really laggy when they all start clumping together, so the best option seems to be to get them separated. I don’t know how I could do that.
Proposed Solution: I could instead of spawning all the zombies at once in the game, make them come in groups over time. I am trying to make a wave-based zombie survival game, and I think that if I allow each wave to slowly allow all the zombies in, that would be optimal, compared to spawning 500 zombies all at once. That would be a nightmare for my CPU. One problem is that if all players die and there is one player left, all the zombies will try to attack the one player and the lag will be unbearable. Is this a good idea?
There are even more problems of the zombies getting stuck when clumping together (as you can see in the video).
Here is a video of the NPCs in action:
As you can see they turn around and try to go around each other, and many just end up stuck.
I thought of creating a hive mind where they all coordinate and attack their target, keeping their distance from each other while moving towards the player, but it is too complicated and I lack the expertise to design it and write the code. I don’t even think I can use PathfindingService
to do that.
Are there any options? I am running out.