Enemy help with grouping

4.4

sorry for the scuffed resolution, how can i stop my enemies from grouping up like this?

this is literally the movement code, as of now they do not have pathfinding (yes there are multiple enemies)

i can provide more info later thanks in advance!

Hi,

One option would be to use some techniques from boids algorithm (used to simulate flocks). The basic idea is that each enemy will try to keep a minimum distance to every other enemies, ensuring they’re not stacking. You can also control that distance to still allow some overlap.
Boids typically have 3 behaviours: avoidance to avoid collisions, alignment to move in the same direction, and cohesion for the boids to stay grouped. You’d probably want to have a look at how avoidance can work.
Here’s a video in case you’re interested: https://www.youtube.com/watch?v=6dJlhv3hfQ0
And a link for a flock demo in browser: Boids: Flocking made simple | Harmen de Weerd


Another solution would be to add collisions to your enemies so that they cannot stack thanks to the engine physics doing its job on its own. You may still have some grouping behaviours, but no stacking. You can again control the collision size to allow some overlap.

I will try those out thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.