Having programmed the Flipping Blocks game and scratched the surface of Unity3d’s capabilities I started experimenting with Unity’s physics functionality. Unity does so much of the heavy lifting that I was able using about 150 lines of C# code to program a nice 3d swarming simulation based on a few simple rules:

try to follow the leader

don’t get too close to your neighbours

slow down if you go too fast

don’t get too far from the camera (leader only)

It makes your hardware work quite hard. I can watch it for ages, it’s quite fascinating.