top of page
Writer's pictureCallum Pearce

Visual Upgrade


After having a basic flocking mechanic working last week it was time to start adding the advanced features that actually made it suit the game being created. Most of this involved a visual design change but a few code changes were made as well.

The first task was to add more fish so there could be different types. This was the simple part just by randomising what fish type was selected. But the next part was more tricky. Realistically fish will tend to only school with fish of the same type, and the way the flocking worked last week meant all fish would just flock together as shown by the image below.

Four different fish type, flocking together

From this it was clear it had to be changed so that the group size would only go up if the fish near it was the same type. Just by adding a int variable representing the fish type allowed for an if statement to solve the problem, but the way the flocking rules were applied meant they would only apply when in a group. This was right, so an alteration had to be made so that the only separation rule applied to all fish. Not just the same fish type. The image below now shows the four different type of fish flocking with their type, and although hard to tell through an image they will still separate from each other.

Four different fish type, flocking separately but avoiding all

By the time this version was ready, the artist was able to create and animate two of the fish models. The Clownfish and Surgeonfish. These models were then added into the scene (but not yet playing animations), and they started to bring some life to it. Therefore just to see how well the program started looking I altered the skybox just to fit the theme to compare to real fish.

Two fish type with models in place flocking with underwater background

To make the scene start comparing to real life the fish needed to play their animations. The animations themselves have been done using blend shapes, and having the tail of the fish bend to the left and right. These two properties were editable in the animation window where the animations were made to start from the left, go to the right and return to the left again for a complete animation. Once the animations were done a controller for each fish had to be made so that they could play and loop. To do this a speed variable was added to each of the animations, allowing for a condition to be added where speed > 0, play animation. Then finally, this speed variable had to alter the actual speed of the fish, otherwise some would go fast, and others would go slow but without any changes in the animation. Finally a small bug occurred when the idle state of the fish had the "HasNoExitTime" property still checked, resulting in the fish spawning at the start, and not playing their animation for a couple of seconds.

As all the animations got added, it was time to have a bit of fun and start bringing up the numbers to see performance on my laptop. At first this did seem like a waste as the final product is to be on a mobile, but actually highlighted a small design change. In the code all fish rely on a "neighbourDistance" variable that checks how far another fish is. If the distance between two fish is lower they will move away for the separation rule, but the distance first set was actually too far, and resulted in the flocking looking a bit off. Bringing down the neighbourDistance slightly made the fish flock closer together, yet again making it look more and more realistic. One final change was made so that the fish could spawn at any point where the spawn wireframe was located, and not just based around 0,0,0. As when this gets added into the final scene, the fish spawn will constantly change throughout the game. Below is an image of 500 fish flocking close together with the changes made above.

500 fish of two types flocking closer together

My task for the next week is to add more fish models with the animations so a full scene showing what it might look in the game can be created. Then to further carry out testing, but on a mobile device rather than a computer due to obvious hardware differences.

10 views0 comments

Recent Posts

See All
bottom of page