When we first started discussing the game’s idea with Roque, and the word mob was mentioned, another word come into mind: “empanadas” (because we were hungry, and we always eat some delicious emapanadas on Fridays). But immediately after lunch yet another word come into my mind: flocking. The algorithm that mimics the coordinated movement of bird flocks or fish schools (Red3d.com) seemed like the way to go. Sure, people were not going to behave exactly like fish or albatrosses, but the three rules that govern the flocking algorithm, separation, alignment and cohesion, were going to be more than useful to determine how the people in the mob behave.
Being the lazy programmer that I am … errr ... I mean, the efficient programmer that I am, and trying to avoid reinventing the wheel, I set out to seek flocking algorithms implementations on Unity. Soon I came across this neat little set of scripts on the Unity Wiki: Wiki.unity3d.com. It was very simple to implement and the use of a centralized controller made it very efficient as well. It allowed to create a mob of several hundred boids at a very low performance cost. So I used this as the mobster’s behaviors' foundation stone. Our early prototypes were all done using a modified version this algorithm.
And so everything was peace and quiet, months went by and the game grew until one day the algorithm was not enough. The game’s needs had changed and it was time to write a new super efficient yet flexible and versatile flocking algorithm … or search the web again. So I did the latter and this time met Unity Steer: Arges-systems.com
Unity Steer proved to be very flexible, you can add or remove different steering behaviour to get different results easily. It seemed just what we needed. But this came at a performance cost. My good old MacBook started to suffer when a couple hundred boids were added.
What I did then was a fiddle around for a while with the different behaviours, to see which combination worked best (and because it was fun to do so, wiiiii, flocking!!!) until I found something I liked and then merged the behaviours together. The next step was doing some more optimization, taking advantage of the mob’s specific characteristics, removing a little bit of this, merging some of that, profiling, adding a little bit of that, profiling again, checking imdb to settle some arguments about Willem Dafoe’s career, removing some more stuff and profiling once more. You know, the usual mob optimization process.
When it was all over, several hundred boids were moving smoothly around the computer’s screen, doing their boiddy things, aligned, separated yet cohesive. The boids were ready to be integrated into the game, to spark some life into those pixelated and angry Greeks. Pure beauty.