Nice job! You just implemented your own swarm intelligence for fish (also known as boid behavior)!

Final flocking fish

Now you have some time to play around with the weights and distances.

The weights we have work well enough but it does take some time for the fish to cluster into coherent "schools". Can you re-weight the values and make them school together faster?

More resources

In this tutorial we covered a few mathematical concepts and basic, "boid"-style artificial intelligence.

We covered:

  • Points in two-dimensional space
  • Vectors in two-dimensional space
  • The difference between speed and velocity
  • How simple rules (cohesion, separation, alignment) can create emergent, complex behavior

Some other boid-style things to check out

  • Batman Returns (1992) used boids for movement of bats and penguins
  • The Lord of the Rings franchise used MASSIVE for it's large fight scenes. It has since been in numerous movies and TV shows. If you see a large, computer generated crowd in a movie, it's probably orchestrated with MASSIVE. Check out their professional demo reel and this real time battle sequence. They've even combined what we learned in this project and in the cruise control project to simulate traffic.
  • Boid-style algorithms can even model opinions propagating through social networks! It is not limited to just movement. Any system of individual "agents" (fish in our case) that change their properties based on those around them can be simulated with boids. This article is a bit of a long read, but very interesting if you want to see how it's done.


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more