Preventing AI from crowding/clustering when chasing a target?

  1. What do you want to achieve?
    I’m trying to mimic horde-like/flocking behavior for my AI/NPCs. They all utilize the SimplePath (with some adjustments) Pathfinding Module to navigate towards the player. A great example of what I’d like to achieve is similar to how Guts & Blackpowder’s zombie hordes work- if they’re too tightly packed, they spread out when pursuing the player. Example:

  2. What is the issue?
    While the AI is excellent at navigating through obstacles/terrain to get to their target-, an “issue” arises when there’s multiple NPCs pursuing the same target. They quickly gather and mass together. Example:

  3. What solutions have you tried so far?
    I’ve searched around the Forum for potential solutions, but I haven’t had much luck. Any ideas on how I can have the AI spread out to prevent clustering, all while keeping in pursuit of their target?

1 Like

you need to add a lot more randomization to the direction and speed

maybe you could set the location they’re moving to be instead of the players direct location, a few studs to the left or right of the players location? then when they’re close enough they move directly to the player, thats not the way guts and black powder does im pretty sure but it might work

A ray with a size of about 1 - 3 studs can be used to detect if any other npcs are in front of the npc so that it can move towards the left or right

1 Like

Seems like a simple problem to be honest. Just slightly offset the target position for each of the path finding. This will cause the AI to look like it will try to “surround” the player.

Also the closer the AI to the player, the smaller the offset.

The method I use is called flocking. There’s plenty of tutorials online to do this. Basically a zombie looks at its close by neighboring zombies, and based on a set of rules decides a new movement vector to align, cohere and separate from each other. There’s no randomization as other people have suggested.

2 Likes

Oh?, I didn’t anticipate getting a response from the man himself.

Do you think you could point me in the direction of some reliable tutorials/information sources on the subject?

I’ve looked into flocking behaviors before, but my main concern with it was how well it’d work in conjunction with ROBLOX’s pathfinding service. How would I go utilizing both flocking behavior, and pathfinding without compromising the AI’s ability to navigate? I imagine the AI getting stuck or halted while trying to maintain its space between neighboring members of the flock when navigating through tighter spaces. I’m a bit stumped on where to begin.

Their flocking isn’t that aggressive. I also disable the flocking when they’re going through doorways and stuff like that.

Okay, after a few hours of research and trial/error- I think I’ve gotten pretty close to what I’m looking for:

It still needs some tweaking, but I’m happy with the progress. You sharing that you used flocking behavior to achieve the desired effect helped narrowed it down for me- I highly appreciate it, thank you!

One last question- what would you say is the best method to help the AI recognize doorways and whatnot?

1 Like