Search Unity

Assets Fish Flock [WIP]

Discussion in 'Works In Progress' started by elvis0234, Oct 3, 2017.

  1. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24


    Fish Flock is a simulation of flocking behaviours of a shoal of fish. It's fully customizable and it uses a separated thread to calculate the flocking behaviours to enhance performance. The group area, defined by the user, can follow a specific target or random points inside another area defined by the user. The first area that follows something defines the space where all the fishes will try to stay grouped, while the other area is where this group of fishes are allowed to swim.

    Besides the separated thread to calculate the flocking behaviours, other features are:
    • Collision Avoidance.
    • Acceleration, speed, force, fish instances count, and other flocking properties are all customizable through the inspector.
    • You can have multiple shoal of fishes on your scene following different targets, with different area sizes and positions.
    • Includes one shader that simulates a fish swimming by animating it's vertices.

    Screenshots:






    Gifs:



    [What the shader does with the fish model]

    Videos:






    Todo next:
    • Calculate the Flocking Behaviours on the GPU instead of CPU
    • Give an option to choose between spawning game objects to represent each fish or just leave it to a shader to render all of the fishes with GPU Instancing (it will be faster since they are going to be calculated with a compute shader already)
    • Wandering Points besides the following a target or random points through the scene
    • A predator behaviour that will scare the fishes away

    This is a WIP project, I already submitted it to the asset store, with the price of $16, and it's pending review, but I'm looking forward to improve this asset, so any suggestions are welcome and I will appreciate it a lot :)
     
    Last edited: Oct 3, 2017
  2. rcalabrezi

    rcalabrezi

    Joined:
    Mar 7, 2015
    Posts:
    2
    Amazing work! I'll keep an eye on it.
     
    elvis0234 likes this.
  3. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    526
    Hey this looks cool, I can imagine a bunch of game ideas for this! haha.

    Can you have collision detection on the individual fish? E.g. if a shark swam through the shoal could he eat the fish he collides with?
     
  4. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Yes for sure! Actually I didnt thought about a shark eating the fishes, this is a good idea, that would be cool for a demo included on the project, I will look into that!
     
    Serinx likes this.
  5. Bartolomeus755

    Bartolomeus755

    Joined:
    Jun 20, 2013
    Posts:
    240
    Looks interesting, great work so far.
     
  6. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    616
    Looks good. I'll watch for any updates.
     
  7. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Thanks!!

    Thanks! There will be updates for sure!
     
  8. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [UPDATE #1]

    I'm testing a predator script that scares away the fishes, I gave a look on some videos about how the shoal behaves when a shark is around (like this one, and this one ) and I tried something similar, when the predator comes to the shoal they separate from that point where the predator is but they still swim around it

    Here is a test: (Note: the sphere represents the predator)
     
    Last edited: Oct 6, 2017
    Bartolomeus755 likes this.
  9. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    616
    Will it be easy for us to use our own custom fish models? Can it cope with different size fish and behaviors? Perhaps you can support aggressive fish (like piranhas, sharks, etc) and defensive fish (attack only when threatened.) You may not be interested in adding that at this point but I thought I'd throw that out there because I think that would be very useful.
     
  10. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Yes you can use your own models. It can cope with different sizes, velocities, etc
    The behaviours contains the same properties and the same values for all the fishes (minSpeed and maxSpeed for example will make a random number between it, but the min and max for the number generated it the same for all the fishes), but it's a cool idea, maybe I could extend the properties so the fishes can attack and be attacked as well, thanks for the suggestion!
     
    StevenPicard likes this.
  11. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [UPDATE #2]

    Still working on the predator, the fishes tries to avoid being inside the red sphere area while steering with the group

    Screenshot:


    GIF:
    https://i.imgur.com/bt56NBI.gif

    (Ps.: Ignore the shark model and his bad movement, its just for testing)
     
  12. The-Britain

    The-Britain

    Joined:
    Mar 31, 2015
    Posts:
    714
    Hey this is cool as hell! Great work!
     
    elvis0234 likes this.
  13. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    526
    This is looking good! I'd love to see a multiplayer game using these techniques. 1 player as the shark, 1 as the shoal. The shoal can morph into different shapes to avoid the sharks charging attacks e.g. donut shape, ball, pole etc :)

    Keep up the good work!
     
    NoctisShadowzel and elvis0234 like this.
  14. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Hey! Just to note, the asset has been accepted on the asset store.
    The next update on it will be very soon, I've made progress since i've submitted it to the store, so, thanks for the suggestions so far and I will update it here as well as soon as I have more stuff to show.
     
  15. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [UPDATE #3]

    Hi! I just sent an update to the asset store containing the predator and a demo showing how it works (it is on pending review mode yet, i don't know how much time it will take to show up), it also contains a new fish model and the predator script to use it in any model you want.

    Screenshot:


    GIF Link: https://imgur.com/bBEL3bL

    Also a youtube video (because the GIF quality was too bad, i dont know why):
     
    Last edited: Oct 15, 2017
    Serinx, StevenPicard and John-G like this.
  16. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [UPDATE #4]

    Hello! In this update I corrected a few bugs happening with the fishes once in a while, like swimming out of the group or out of the boundaries. And I also added a new demo showing how to use a new small feature that I added which is adding a script to modify the fishes behaviours while they are being updated.

    Some other good news is that a few people bought the asset and i'm very happy with it, unfortunately no one reviewed it yet but I hope I can get some reviews soon so I can improve this asset to make it even better!

    Here is a video from the new feature:


    And a shorter version of the video as a GIF:


    I will update the asset today and I think that it will take 2 or 3 days to update on the asset store.
     
  17. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [UPDATE #5]

    Hi! It's been a while since I don't post here, the asset changed a little, and a few bugs were corrected.
    First of all, now the inspector contains three more variables:
    - Separation Scale: When calculating the steering forces, there is a separation force that eash fish applies on to another so they don't overlap each other all the time, this separation scale can be decreased or increased and it defines how much you want to see the result of the separation calculation.
    - Alignment Scale: This force is applied to the fishes so they swim more aligned with each other and not too random.
    - Cohesion Scale: This force will define if the fishes will swim too similar together or they will split up more without a caring too much about the shoal.

    The particles that fishes uses changed a little too, it's a little better now I hope.

    There was one bug happening in two different situations, both of the situation were making the fishes swim away from the target and the shoal itself for no reason at all, the core code was changed, and an adjustment when deleting fishes on runtime (like when the predator eat them) was made, there was a little bug between the thread that calculates the steering forces (the parallel thread) and the main thread (unity thread), they were holding a reference to the same list of fishes so when one of them was modifying it while another was using it, it was causing this weird behaviour.
    The asset was tested twice with 15 minutes of simulation, the bug didn't seem to appear anymore, but for anyone that has this asset you can send me an email (elvis.leite.9@gmail.com) and I will look into it.
     
    Last edited: Feb 5, 2018
  18. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    329
    Interesting asset and looks like something I can use for my game. Is this still being maintained? Aside from fish, does this support other models as well like maybe jellyfish and octopus? It would be great if some AI behaviors can be added to this like the fishes migrating to another part of the map after a certain period of time or maybe when water temperature is warmer or colder, etc.
     
  19. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Hi RendCycle!

    Yes, this asset is still being maintained, the last last (version 1.21) was on May 18, and yes i'm still planning for more updates and additions.

    So, yes this behaviours can be added but they are not included in the asset, you can do that but there is no like prefab script ready for that, but thats a very good idea, I could add something like that in the next update, would you be interested?

    And about the models, it doesn't obligate you to use only fish models, you can use any models, but the behaviour of the asset is focused on a shoal of fish, but yes you can use whatever model you want.
     
    DrOcto likes this.
  20. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    329
    Yes, I would definitely be interested as I may then be able to connect this to a Weather System that can be used to identify the water temperature and therefore the location of the fishes. To expand further, this can probably also be used to identify other triggers too that can control the behavior of the fishes whether they will move away from multiple threats or just stay where they are and whether they can jump over water, etc.

    Another important feature for me right now would be to be able to "catch fish" when a particular object, like maybe a net / harpoon, collides with it and the creature's Evasion Points is less than the Accuracy Points of the item used. The group of fishes should then be reduced to the remaining fishes that were not caught. I'm not sure if that is possible but it would be great to have and will make this a definite must buy.

    I have a few more questions... I'm also wondering how does the Predator feature work and how many number of fish models is the recommended maximum per group?
     
    Last edited: Jun 16, 2018
    alexanderameye likes this.
  21. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    329
    I'm really tempted to get this asset even if it still does not have all the functionalities that I need. I might just modify it if i can. Anyhow, I would like to know more how it works and if it will fit my basic requirements. I have seen the screenshots of the Inspector and I have these questions:
    1. Can I use different fish models with animation? I'm planning to add jellyfishes and other fish types.
    2. Would it be possible for me to add Life/Hit Points per fish/creature in a flock?
    3. Can there be two or more flocks of fishes in a sector? What happens if they cross with each other?
    4. What does the Random Target Points Following do?
    5. What does Swimming Area Depth do? Would it be possible to make fishes jump over water?
    6. How does Attack work? Does all the fishes in a flock make the attack?
    7. I saw the Predator header. What does it do and how does it work?
    8. What is the Gfx section for?
    I'm comparing this with another Fish Flock system in the asset store and I would like to check which one is the closest to what I need. Hoping for your prompt reply. Thanks!
     
  22. DrOcto

    DrOcto

    Joined:
    Sep 15, 2017
    Posts:
    79
    Hi :) well it is a nice flocking asset but i would like to ask can it be used to simulate maybe ants or bees? Insects that fly are some how like the fishes just in the air :D or maybe birds. Thanks for a reply.
     
    Last edited: Jun 23, 2018
    RendCycle likes this.
  23. DrOcto

    DrOcto

    Joined:
    Sep 15, 2017
    Posts:
    79
    Hi, just asking will it have in the future some flocking on ground (Ants) but they must STICK on it to be more clear on it. So you can have spiders, ants or what else that can crawl over wall or ground also. I know it is a fish flocking asset but this looks so nice that it would be a shame that it was not expanded more. ;)
     
  24. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Hi, sorry about the delay!

    1. Yes you can, I will also update the GPU flocking version with the ability to apply an animation clip (one only)
    2. Yes it is, on the CPU version there is an array of a FishBehaviour struct, you can modify it
    3. Yes you can have more than one flocks with the CPU version, with the GPU you cant but i'm sorting it out, when they cross nothing happens, they just care about their own flock, but that would be a good idea, I will write that down and keep it in mind to have like one central script and more than one flock
    4. It creates a random path inside the swimming area so the fishes can swim through it
    5. The Swimming Area Depth it's just the size in the Z axis of the swimming area. No fishes cannot jump over the water
    6. Yeah so the Attack its pretty simple, they just pass over the target multiple times, this feature I started but didnt got much further
    7. This is a bigger fish the pursue the flock, and when it hits one of the fishes, it destroys it and a simple blood particle is spawned, its just a demonstration of what could be a shark attacking the fishes
    8. You mean the GFX section on the Fish Flock GPU? There are 3 items there, one is the Compute Shader that is used to calculate the fish behaviours in the GPU, the other is the Mesh of the fish, and the other is a instanced material to draw all the computed fishes with the same material
     
    RendCycle likes this.
  25. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Unfortunately it doesnt focus on this type of flocking, ants and bees behave differently and yes with some modifications this can be closer to what you need, but the focus is the fish flock only, update it to adapt to a more general purpose would maybe disturb other people that are already using it the way it is, so if I would do something like that I would make on another flocking asset
     
  26. StevenPicard

    StevenPicard

    Joined:
    Mar 7, 2016
    Posts:
    616
    Creating additional assets for those behaviors might be a very good idea. ;)
     
  27. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    825
    Flocking good! Can I purchase now, or when/if will it be available?
     
  28. DrOcto

    DrOcto

    Joined:
    Sep 15, 2017
    Posts:
    79
    Thank you for your answer. I do get it that it is something totally different but had high hopes but well you said it will come in a next asset then ;):D. You are on my shopping list very very soon :) Maybe best asset that i have seen here that is doing fish flocking!
     
    elvis0234 likes this.
  29. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Iit is available already here
     
  30. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [Small Update]

    I've been working on a better flocking behaviour for the CPU version of the flocking fishes and I come to a conclusion that I will leave the current script of the CPU version as it is, without modifying it to not harm other people that are using it, and I will add a "Fish Flock Controller V2", it will have an algorithm more similar to what the GPU version is, because when the GPU version was implemented I did the algorithm different because it was smaller and more efficient, it also produced a better(at least is what it seems) behaviour than the CPU one with less variables. So to preserve the current configuration that some people that bought might have, I will add this new Fish Flock Controller CPU, I will give the option to use it normally, or multithreading or with an instanced shader (the previous Fish Flock Controller CPU does not have an instanced version, then it will probably also support an extra thread calculating the behaviours of the fishes and an instanced shader rendering it, here is a small video with the instanced version using just the main thread to calculate the behaviours:

     
    Serinx, RendCycle and StevenPicard like this.
  31. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    [ Asset Update]

    Hey guys! So, I finally updated the asset on the store, it took me more than I thought, also I was very busy during this period but I finnaly updated it.

    - Added Fish Flock Controller V2, which is basically the normal Fish Flock Controller that runs on the CPU, but with a behaviour more similar with the GPU version, and also with instancing support
    - Multiple instances of the GPU version on the same scene are now allowed, you must have one material per object with the GPU flocking script
    - Added the ability , for both GPU version and CPU version V2, to make the fishes swim only on the XY axis or just XZ axis
    - The GPU demo now has 4 showcases totalizing 10k fishes in the scene

    https://assetstore.unity.com/packages/tools/ai/fish-flock-100717
     
    Serinx and alexanderameye like this.
  32. sudar0627

    sudar0627

    Joined:
    Mar 28, 2017
    Posts:
    2
    Hello.

    I tested a predator demo,

    There seems to be a problem that fish do not avoid.

    I was analyzing the script, but I couldn't figure it out.

    Please check if you have any bugs.

    And if it's not a bug, ask for a simple tutorial or inspector to tell you the setting values.
     

    Attached Files:

    • fish.png
      fish.png
      File size:
      321.2 KB
      Views:
      216
    • fish.png
      fish.png
      File size:
      321.2 KB
      Views:
      219
  33. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Hi sudar0627,

    what does the fishes do not avoid? The shark?

    Its been a while since I edited this demo, it may be outdated as I was giving the GPU and instancing more attention a while ago
     
  34. sudar0627

    sudar0627

    Joined:
    Mar 28, 2017
    Posts:
    2
    ///////////////////////////////////////////////////////////////////////////////////////////

    Hello, Elvis.

    Thank you for your answer.

    In the test clip you showed, you can see fish running away from the Predator component object, which means that fish do not avoid the Predator.

    As you can see from the screenshot I attached, I tried to get rid of the shark's movements and move the shark towards the fish myself, but the fish are holding back.

    I want to implement it like a test video that you showed me. Please tell me how to solve it.
     
  35. elvis0234

    elvis0234

    Joined:
    Apr 15, 2014
    Posts:
    24
    Hi sudar0627,

    Its been a while since you posted here but I've been busy with full time work in the last months, but recently the asset has been updated and I found that the fishes were not evading the predator properly, so you can maybe test it now if you still have interest, but you can also use the GPU version that currently has box colliders support and you can move them around the scene and the fishes will avoid it, you can use it as a predator as well, the recently updated version has this feature.

    Sorry for this inconvenience and delay time, let me know if there is anything else I can help

    Thanks