Fish Schooling

Hey forum,

Firstly thanks to the Unity team for a great product, v3 was just in time for this project. I am new here and have been steadily learning Unity for the past couple of months.

For a recent project I needed to create fish schooling, here is a screenshot…

There are 54 fish, all with a 7 bone structure, not all are salt water, just recycled from our library… originally purchased from turbo squid. As a test, I have run up around 130 fish on a default background before my laptop would start to drop frames.

All the fish run the same code, although they seem to exhibit different behaviors… basic collision detection is still work in progress. I have used message broadcasting for the schooling, each group has a range, safe zone and single or multiple targets.

Here is the webplayer… http://www.doubledigital.com.my/Unity/FishSchooling/webplayer.html

Enjoy.

Thanks to Sandor for his examples, yes someone eventually reads your posting :slight_smile:
Also metervara for the great Red Snapper demo.
Lastly, thanks to Rod Hyde Magnus Wolffelt for the Csharp Messenger example on the wiki.

You need to fix your link: http://www.doubledigital.com.my/Unity/FishSchooling/webplayer.html

Edit: Looks really nice.

I would prefer it if it was zoomed in further so we got some nice close ups of some fish at times.

That’s truly lovely. I especially like how you kept the shark “lurking” in the background, adds a lot of depth to the scene. I’d love to learn more about how you did the water and godrays. Is that the standard Pro water and god rays? How did you get the lighting so nice? Any hints would be appreciated.

Thanks.

Yes it is standard Pro water, with the new sunShafts and bloomAndFlares image effects, 2 directional lights with cookies for the caustics effect (See the Red Snapper example)

I still need to adjust the procedural animation, some clunkyness in the movement and collision detection. And I would really like the fish to scatter when the shark is nearby.

Yeah, I think they call that “predator / prey behavior” and I’ve seen demos of it but I don’t recall anyone here doing it in Unity yet. You’ve done a really nice job, the lighting, colors and animation make it very dramatic.

Thanks mate. Will post the next version when I’m happy with it… getting there although now some schools have a case of Parkinsons.

I think it’s also called “fight or flight” response.

I haven’t yet had a look at the behavior trees from Angry Ant, maybe well worth a look.

Looks great. Unitysteer http://www.arges-systems.com/articles/46/unitysteer-updated has what you are looking for I believe.

Great graphics, keep up the good work!

Thanks for the tip.

Thanks tried it and seems to be good for a few objects and nicely modular. Using Steer for more than a dozen objects other than cubes really slows down. Maybe I’m not using it correctly.

It looks really good.
I’m working on underwater game prototype and I hired a programmer for fish school behavior.
he used Unity Steer for fish school but It really slow down when there are a lot of fish.
so I decided to not use Unity Steer. still looking for a good solution for fish school behavior.
I really like your fish movement so far. Great Job!!!

Hi Dakka,

I’m curious about what kind of performance people are getting - how are you using it? Also, could you look at this example and let me know what kind of performance you get?

http://www.arges-systems.com/examples/36/unitysteer-boid-example

That uses the old UnitySteer 1.0, which was not optimized at all. Since the current version is faster, that test should act as a sort of worst-case scenario.

Cheers,

Hey Ricardo,
Thanks for your reply and thanks for sharing UnitySteer.

Sure no problems with that example no dropped frames, similar to the example with the download of UnitySteer which has more cubes.

While I can see the benefits of UnitySteer, the limits I faced used a prefab consisting of a skinned mesh with a 7-bone hierarchy and hinge joints. I also looked at using followers etc. My scene has about 8 groups of fish, and I would really like to try and not to use a follow the leader method for the smaller schools closer to camera. For a larger school as background detail, sure that would be my approach.

I’m still looking for an ideal solution…

Hey Dakka,

My pleasure, but it wouldn’t exist without Craig Reynolds’ steering work and his initial sharing of OpenSteer.

The boid scene does not use a follow-the-leader approach and the behavior is completely emergent, so it might be a good starting point for you. One could of course also add a “SteerToFollow” behavior, perhaps based on SteerForPursuit, on top of the SteerForNeighbor behaviors if that were desireable.

Regarding performance, I was thinking there are two major areas one can look into right away (other than the profiler, of course):

Radar radius. The default RadarPing is very basic, and checks against the position for each item it detects. This means that for a group of n vehicles within radar distance of each other, it ends up being O(n^2). This can be handled in several ways:

  • Reducing the radar radius. Not every member in the flock needs to be aware of every other member’s position in order for the flocking behavior to work, so reducing the RadarPing’s radius might be a good way to both increase performance and get more interesting behavior.
  • Implementing a more sophisticated radar descendent, for instance based on Octrees.

Tick frequency. The default tick frequency provides for updating the radar every tenth of a second, I believe. This might be overkill for most cases, and if the radar is indeed the bottleneck one could also increase the time interval, to avoid getting unnecessarily frequent ticks.

Still, the web example I linked to is over one year old, and didn’t even have the Tick as a performance gatekeeper, so there’s likely something else going on if it’s slowing down with a mere dozen vehicles. If you check the example currently on Github, it uses about 220 vehicles with a rather eager radar ping of 0.1s and a detection radius of 7, and runs on my machine at about 5-7ms per frame (an average of 160fps).

Hopefully this helps you guys. Cheers,