The Boids Swarm project is an Unreal Engine 5 project that uses a boids framework similar to Boids In Combat to create an algorithm which can simulate insect or bee swarming. While the previous project focused on simulating the general movement of different groups, the primary goal in this project was creating detailed movement.
To start, I spawn a number of boids (in this case 150) in the scene and give them nothing more than the standard forces of alignment, cohesion, separation, avoidance and target seeking to create their emergent behavior. A target is placed somewhere randomly, and they immediately enter the first phase of the swarm as they seek their target. The movement during this phase happens in a loose cloud formation as each of them beelines towards the center of the target. Once they arrive, however, they enter a second phase of the swarm in which they form a busy cluster around their target.
The cluster is formed by choosing points on the surface of a sphere formed using the target’s location as a center point and a radius of 250 centimeters. Once a boid has chosen a point, they steer to that location rather than the center of the target. Each of them are selecting between 300 points on the sphere to create enough diversity in their movement for the chaos of the swarm to emerge. They also move quickly, which leads to them overshooting their targets and gives a more natural feel to their swarm.

I also wanted the swarms to travel between different target locations and handle avoiding obstacles. After a certain amount of time, I move the target to a new location and send the boids on their way. They need to use a similar calculation to the one above to find a direction that doesn’t result in a collision for them. The difference here is that they can stop calculating once they’ve found a valid direction. This gives us the behavior below, where we see the boids flying around the tower in the center to get to their desired location.

While I am happy with the final behavior that the boids exhibit, I would still want to improve this project by moving the swarm calculations from the CPU onto the GPU. In the current implementation, the calculations can get intensive and drag down the frame rate when the boids are avoiding collisions or calculating points around the target. While lowering the resolution of the sphere used for calculating the swarm could make the CPU implementation faster, moving the logic to the graphics card would still dramatically increase the performance. This would allow scaling the scene with more boids and more obstacles without compromising frame rate.


Leave a comment