Haven't posted in a while, recently I wanted to learn how to animate a group/flock of fish in Unity.
I ended up using shadergraph to animate the individual fish and created a script to control the group motion at run-time.
The flock simulation is called Boids, and it was originally developed by Craig Reynolds. The code I wrote is relatively simple (has 3 main steps).
Separation:
1) Avoid colliding with other fish
Alignment:
2) keep average alignment of nearby fish
Cohesion:
3) move to the average position of nearby fish
