I’m currently creating a Zombie AI that uses a boid-like separation system to keep zombies from getting to close to one another, but this is causing some issues.
When it comes to obstacles like corridors, due to the zombies separation, they’ll walk on the sides of the walls rather then properly adjusting their spot in the separation to fit through the corridor, causing issues like in the video attached.
Does anyone know methods for detecting spots like this to properly “squash” the zombies inwards so they can go through spots like this?
For context, zombie separation works like this :
Each zombie applies a repulsion force away from nearby zombies inside a radius, and I blend that with their movement toward the player. The problem is that in tight spaces, the outer zombies keep trying to maintain their normal separation distance, so they end up riding the walls and getting stuck instead of compressing into a narrower formation.
What I’m looking for is a clean way to detect when to temporarily reduce or reshape separation, this way zombies can properly fit through corridor like spaces.
For a zombie, generate a circle of raycasts around the zombie, maybe every 45 degrees or something. Then get the surface normal and distance of each raycast, and go through every raycast, deleting ones that are similar to each other, but trying to keep the raycasts with the shortest, and most different surface normals. Finally, see if the final group of raycasts has 2 raycasts that are have almost opposite surface normals, and their raycast lengths added up are short.
If these two raycasts exist, the zombie is probably in a corridor, and you can decrease the seperation of that zombie and maybe nearby zombies.
Maybe there are a few areas where this system could be improved, but hopefully this works good enough.
Sorry if this wasn’t explained very well, I could try and explain it again if you don’t understand it, maybe with some images too.
Also, creating raycasts for every zombie may be a bit resource intensive, so maybe there is a way to select which zombies to run this on, but maybe this is okay to keep how it is.
btw I made this up like right now, so there may be better ways out there.
I hope this could help! and I would be happy to explain this better if you didn’t understand it well!
Ended up fixing it, I use the players point as an “anchor” and before separation points are generated, I make sure they’re within the walls by casting to the players anchor point, need to optimize this method heavily and there might be a better way, but it works for now.