Summer is over. Senior year. First week of school. Labor Day weekend. You know what that means... IT'S BOIDS TIME! Wait, I know what you're about to ask. "But Elijah Cirioli, owner of www.elijahcirioli.com, what is a boids????" Excellent question, dear reader! Please click my ads. I had a little extra time because of labor day so I did what I always do with my extra time: I watched YouTube. Through the magic dartboard of YouTube recommendations I came across this video by a guy named Sebastion Lague. It's a pretty neat video that gets into some 3D stuff that's too advanced for me but my main takeaway from it was that boids exist and I needed to make some.
Picture this: the year is 1987, The Simpsons have just appeared on television for the first time, Ronald Reagan has just given his famous speech in front of the Berlin Wall, and most importantly, computer graphics specialist Craig Reynolds is about to release his groundbreaking research paper Flocks, Herds, and Schools: A Distributed Behavioral Model. In this paper, Reynolds describes boids, a model for simulating emergent flocking behaviour not dissimilar to that of birds or fish. The concept is very basic, with only three simple rules one can create varied and adaptive flock behaviour at little computational cost.
What are those three rules? Hold all questions till the end, please. All boids are just a collection of 2D vectors. At the beginning, the boids are spawned in with a random position and a random velocity vector. Each game tick, the three rules are applied, creating three additional vectors which are then added to the current velocity vector and normalized to a set length. These vectors can also be weighted in different amounts to produce different types of emergent behaviour, which is something I have implemented in my version. The last item I need to discuss before I get into the rules of boids (it's suspensful, I know) is how an individual boid perceives its environment. Boids all have a defined view distance that specifies how far they can see and view angle that specifies their field of view. In my implementation, this translates to boids being able to see all the boids within around a 100 pixel radius of them, but not directly behind them. The boids that they can see are referred to as their neighbourhood.
don't talk about boids separation. Put simply, boids will try to steer away from all other boids within their neighbourhood.