Separation with Pathfinding

A few months ago I made an AI system that would try not to hit each other(I made it for cars, but I think it is possible to make it for normal NPCs too.) Here are the ways I can think of:

  1. Now, if it is just a few, raycasting could help you but if it is not, I can feel the lag from here if you use raycasting.
  2. If only a script is leading a group of zombies(Which I highly suggest, like one script leading 20 zombies at once, that would reduce lag. Check this topic to see what I am talking about.) you can write a formation script which will make zombies to move to the closest formation position by calculating CFrames from a leader zombie. However, formation needs to be broken in narrowed areas. Shouldn’t be hard to break formations for those cases.
  3. Also you can check the area of the zombies. Let’s say, if zombies’ are moving with a loop that has 0.5 seconds(Which would move zombie 8 studs each loop if zombie has 16 speed) you can check that are and see if there are any zombie around close-by. Zombies close-by can think of going as a horde in those situations. CFrame calculation here again, hordes should try to be same type of zombie(Since speed can change depending on type, I think?) and try going shoulder to shoulder. That would give a nice look.
  4. Another way of doing what you want is to increase the ways that zombies can come. Eventually, they will pick different ways. This would decrease unnecessary calculations for formations. But this time when they are about to attack to a player, you should code them like to surround the player. For example, make only six zombies get near to a player at once and keep others right behind but not attacking. CFrame calculation again, but much lesser than 2 and 3.

Best option there is to use 3 and 4 together but not forgetting the link that is provided in second way. Good luck on your project!

3 Likes