during Game Access 2010 there was one nice technique mentioned "by the way" as approach used for modelling chicken flock animation - the boids.
I googled a bit on the topic, it seems it is one of the most elemental algorithms for group AI, but I like it very much so I present it here in version, where "boids" (individual members of flock) are visualised as simplified fishes in the sea.
The code is organised again around entities and concept of actors and animators I mentioned a while ago. It is very close to OOP and for now it seems very natural way to implement ideas in TB (at least for me ).
The actors are the boids, that means fish in this case, the animators handle the flock behavior. There are two flocks in the demo, one are prey and second the predators.
The code is strongly based on great pseudocode from here:
where the 3 main rules - position, collision avoidance and speed matching are discussed in detail and very clear fashion.
You will need thinBASIC 18.104.22.168 + latest TBGL to run it (or anything newer).
It is not meant to be visually very impressive, I could create model for the fishes and animate it, but I wanted the code to stay as "pure" for general boids as it could be, so others can use it in their projects. That is why fishes are represented just with elipsoids.
As said before, code is strongly OOP, so you can "instantiate" as many boids and their flocks as you need in your projects.
The main application can be launched from Boids_DemoApp.tBasic, the actor_boid.tBasic and animator_boid.tBasic are just "units" used by the main code.
I hope you will like it,
UPDATE: Added new download of BoidsEnhanced.zip where you can play more with the script:
- Arrow keys to move view
- F5, F6 to change area used for prey
- F7, F8 to change area used for hunters
- F9 default camera
- F12 hunter camera