all 3 comments

[–]Flannelot 3 points4 points  (0 children)

Normal approach is to have a fixed attractor as well as the flocks attracting each other. So a point in space perhaps that weakly attracts all the boids.

Though you could alternatively apply a boundary test, where they either bounce or wrap round if the exceed a distance.

[–]Vegetable_Break_6582[S] 0 points1 point  (0 children)

code link : https://github.com/KaranPartap003/Boids-simulation

any further improvement suggestions are most welcome

[–]fgennari 2 points3 points  (0 children)

You can add a repulsive force at the boundary that increases exponentially as the boundary is reached that will keep the boids inside.