Flocking & Schooling System Part 1: Fish


Hi Everybody,

Jack here again, how’s everyone doing? I have quite an interesting topic to discuss and showcase today, that is schooling/shoaling never know which way round it is?!

But in this post I will showcase our new flocking system prototype that I recently built for first prototype segment in the game, which I am afraid to say still doesn’t have a name…. but you’ll be pleased to know we do have our first piece of concept art which you can find over at our website Inverse Studios and be sure to check back here for Kate’s post on how she went about making it and where she draws her inspiration from, exciting stuff!

Back to the topic at hand, within this post I intend to give you a brief overview of how I designed it and the way it works, with finally showing you a short demo of it in action!

Before I get in to the design in the next section, I’ll let you in to a little secret to the development of this project, that really isn’t a secret but nonetheless is worth knowing and that is *drum roll*… We follow the agile software methodology that is a mixture of scrum and waterfall, which we like to call “Wagile” cool right?!

So why am I telling you this, well quite simply this is the way in which I like to structure my development posts following a similar workflow i.e. Design -> Development -> Implementation.

So with that in mind lets get to the nitty gritty!


The way in which I like to work and draw inspiration from is before starting any system, mechanic or game loop is to look at other similar implementations in games, apps or other software that achieves a similar result with this flocking system being no different

Having recently played a game that contained make shoals of fish (MANY!) I turned to Abzu to draw a lot of inspiration and drive for this system and boy does it do shoaling well and is also the spiritual successor in a way to journey so you know’s it going to be a fantastic game, as it was still fresh in memory and I it made enough of an impact with me that I still remember the way it looks and feels in game, which as you know is important and not many games seem to achieve that these days.

Although Abzu is great, it is a little extreme for my purpose so I also looked at other implementations that were closer to my needs, them being Finding Nemo & Dory, Uncharted 4 ‘s shoaling system and just flocking assets on the unity store, unreal store and YouTube for flocking in general.


Why I am telling you all of this and how does it fit in to the design process I hear you say, well I am glad you asked!

When I look at Abzu and the shoals of fish, I see multiple shoals of fish that don’t inter-mix with other shoals of fish but do overlap, which is a quite apparent in the image above.


So the way I took that to mean from a design point of view, is actually quite easy in that each shoal will have the same attributes to all the other shoals in the world.

Let me explain what I mean, with discussing the main attributes of the shoal, each shoal will have:

  • A max number of fish
  • A max number of neighbors
  • A neighborhood – that is the entire flock
  • And lives in a global area of flocks

Each shoal makes up what I like to call flock boxes that as stated above belongs to a global flock box, which you can see in the screenshot I took below.





Now that I had the research under my belt, I could use it as my ammunition to develop a simple system following my design within Unity (as it’s very fast for prototyping), which you can see below. Note: we have not yet chosen Unity as our game engine, we are still debating that.


With the magic that is Unity Editor Scripting, I threw a few labels and wire cubes in there for visualization, but will also aid the designers later down the line, when utilizing this system. As you can see in the screenshot I took above, there is the global flocking area that as we stated is refereed to as the global flock box with child flock boxes that act as the parents to the flocks.

And if you know agile, which I am sure you do 😉 you work off of your requirements, OOAD, user stories and all that good stuff but I will stick to just some of the functional requirements for now but nothing too drastic don’t worry!

So I knew that each flock fish would have a set of criteria that it needed to meet and needed to be developed and tested, but as I said I will stick with the main ones for now:

  1. Who’s my parent?
  2. What neighborhood do I belong too?
  3. How many neighbors do I care about?
  4. When do I shoal?
  5. Where do I shoal?

I won’t go in to much detail with each one of these as it will bore you, but I will give you a quick run down.

Each shoal has a parent that is dictated by the flocking manager that holds a list of them, all the fish cares about is who’s its parent and that is simply done through an unique (foreign if you roll that way) ID.

The next item is more non-functional than it is functional as it plays a big part when it comes to efficiency and speed of the system but nonetheless is functional in that it some how it needs to know of its neighborhood and it’s neighbors. This time it is decided by its parent which holds the shoal list and the number of neighbors each fish should care about and school with, as fish sometimes may want to school in small numbers or large bait balls, you don’t know with fish! However this unit though will be decided by the game designers.

I won’t get in to the algorithm that is shoaling/flocking as there are so many more people that can explain it way better than I would be able to but I will tell in which way I went about it and that was by simply doing a sweep and prune of my nearby neighbors and then if I’m within distance of a neighbor I will school. I may ask help from a bitonic sort if the flock is intended to be GPU bound, which is dependent on it’s size as you don’t want to make a small shoal work off of the GPU as there is quite an overhead when it comes to dispatching and all that jazz

Lastly, where do I shoal well if I am schooling and not just swimming about you tend to see that the shoal follows a random pattern, path or even leader depending on the breed of fish, this goes back to requirements but as I wanted all options available for the designer to use, I tend to develop each behavior and again there are plenty of other better people that can explain those patterns than I, but for now I will stick with the random pattern as it’s the easiest.

Each shoal will each have a shoal goal and this goal periodically will change it’s position within it’s shoal that the fish will follow once they themselves are in a shoal that leads to a unique flow.

I said I wouldn’t bore you but I went and did, sorry! 😀


Now, to what you’re all here probably to see the shoal do and that is to school which you can see below! I initially wanted to go deeper in to the implementation of the system but as it’s not the finalized version I will come back to this, where I will discuss moving the processes and calculations on to the GPU via a compute shader or even CUDA in more detail, with a comparison to the CPU version and I might throw in a quick discussion on the algorithms but I will most likely continue to use the bitonic sort.


You’ll be interested to know with the current system I can have a few shoals that have a good number of fish running on the GPU at a stead 80fps+, which isn’t too bad if I say so myself! And don’t you worry as soon as I have ironed out the kinks I will most surely update this post with all stats and more examples, wish me luck!

As always, thanks for your time!




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s