- Home /
how to avoid enemy flocking
Hello there. I am making a 2D top-down shooter game. Recently, I have been noticing the enemies flocking together, which was something I don't want. Anybody out there, if you have a code that works, please post here.
Answer by logicandchaos · Jul 07, 2020 at 01:37 PM
you can just check the distance of the other enemies and steer it away from them, you can use vector2.distance or OverlapCircle, or even a trigger collider. I would probably use OverlapCircle, or trigger collider to get all the nearby enemies, then I would use vector2.distance to find the closest one and then steer away from the closest one.
Or another approach you could get the coords of all enemies and average them, then steer them away from that average point, that should stop clumping..
Your answer
![](https://koobas.hobune.stream/wayback/20220613002651im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Minion floating healthbar over the head 1 Answer
Floating player.... slowly rises when walking around 1 Answer
Unwanted Character Controller Floating 0 Answers
Player floats in air when jumping 1 Answer
Realistic boat movement 2 Answers