Search Unity

[RELEASED] Flock Box DOTS 2.0 - Flocking simulator

Discussion in 'Assets and Asset Store' started by check_marc, Mar 19, 2020.

  1. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    Flock Box is a highly customizable flocking simulation based on the Boids pattern. It is easy to add and tune behaviors without any scripting at all, but it can also be extended with custom behaviors.

    boid.jpg

    Included behaviors
    Alignment,
    Cohesion,
    Separation,
    Containment,
    Seek,
    Pursuit,
    Arrive,
    Flee,
    Follow Leader,
    Avoidance,
    and Wander.

    Individual behaviors can be combined to create compound behaviors. For instance, Wander + Seek produces Foraging.
     
    Last edited: Jul 23, 2020
    Ali_V_Quest and Neviah like this.
  2. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    I bought your plugin recently and it is quite good! I really like the modular design for the behaviors. I did run into small problems and have some questions.

    I am trying to simulate a herd of animals (in this case deers). Things are looking good, but one thing that is bothering me is how fast the boids turn. It seems to do this behavior where it looks left and right in continuous and quick burst. Unfortunately this looks a bit weird and almost jittery in some cases. Is there anyways to smooth out the left to right behavior? I know you are using a lookat(velocity) function and you can certainly smooth that out, but I wanted to see if I could approach that issue directly.

    I took a video of a herd of deer using your plugin and the terrianboid example:


    The other question I have is is there a way to have a queueing behavior with a group of boids? I'd to replicate a behavior you occasionally see in herds and schools of fishes, is where they line up rather than just bunch up together. This is something I'd really like to implement in the future.

    Here is a image and article about the queue behavior:

    https://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-queue--gamedev-14365
     
  3. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    Thanks!

    Twitchy movement can be a recurring problem when trying to find the right balance of steering weights and speed/force. In this case I would recommend lowering the Separation weight.

    That being said, I recognize that some secondary smoothing can be really useful for getting your behavior all the way to where you want it to be. In v1.6.1 I've started experimenting with a script called TwitchDampening (see the the ColliderAvoidBoid prefab for an example; it is applied to the child "pyramid" object). I'm considering rolling this functionality into SteeringAgent in a future update, but I don't necessarily want it to be the first solution users turn to because it won't always be able to hide an underlying issue with the weight tuning.

    I'm adding Queue to my backlog of steering behaviors to implement. It will require some minor changes to the way neighbors are discovered (currently they will only look within a radius around the agent and in a straight line ahead), but it seems like a worthwhile feature!
     
    mandisaw and Berserker44 like this.
  4. Berserker44

    Berserker44

    Joined:
    Sep 1, 2013
    Posts:
    29
    Thank you so much! i'll try those adjustments you mentioned.

    I am really excited to hear you are considering the add the Queue functionality. I think that would really help out with different flocking scenarios ( school of fish, crowd of people, army formations ect. )
     
  5. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    219
    Hello,

    Does your system allow the flock to fit inside a specific area ? for instance an aquarium, i dont want the fishes to swim outside the area, is this possible ?
     
  6. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    Yes, that would be controlled by the Containment behavior.
     
  7. lordlycastle

    lordlycastle

    Joined:
    Jan 25, 2015
    Posts:
    2
    Does this use ECS? Or does this run on CPU on main thread? Do you have any bench marks for specific hardware? would be helpful to see that in description. Both on mobile and PC would be awesome. Stop

    Anyways awesome work!
     
  8. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    Thanks! The next update is going to include a DOTS implementation (and require minimum Unity version 2019.4 LTS). I don't have a release date but it's currently in development. For the moment everything runs in the main thread. I'm going to follow up with some benchmarks soon.
     
    Last edited: Jul 23, 2020
    DwinTeimlon and Gekigengar like this.
  9. ntgCleaner

    ntgCleaner

    Joined:
    Jul 9, 2020
    Posts:
    27
    Great work with this! The amount of customization is very impressive! I've been starting to pick apart your code a bit because I would like to add a "walk" speed, with `maxSpeed` being as fast as the objects move only during fleeing and/or avoiding or the like. I am working on herding sheep and I'd like the sheep to casually stroll as they are "eating" (using the arrivalBehavior) and when being forced to move by the shepherd or dog, they pick up the pace depending on how close the opposing actor is to them - or possibly act a little more erratically when being chased by a predator.

    https://giphy.com/gifs/LOKZiyI8NxJfsLr2Mm

    If you have any suggestions for a min/max speed within your code, I'd love to hear it. Again, very nice work!

    Oh, another question that I'm going to dig through the code for: Does an object HAVE to be nested inside of the flock box object for the boids to interact with it? I was able to get my terrain working properly outside of the box, but I can not seem to keep my player outside of the box and still have the sheep avoid him.
     
    Last edited: Jul 23, 2020
    RomanDogStudios, Dhagz and wetcircuit like this.
  10. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    I've made stress tests (Windows + Android) available for download here:
    https://cloudfinegames.itch.io/flock-box

    On my i5 + GTX 1080 I can comfortably run 1000 agents at 60fps. Beyond that it begins to dip unless fidelity is reduced.
     
  11. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    I would recommend having two BehaviorSettings and using a state machine to swap between them. One would be "Grazing" and have a lower maxSpeed. The other would be "Fleeing" and have a higher maxSpeed as well as a Wander behavior to add some erratic movement.

    You'll be able to detect if a SteeringAgent is fleeing using this line:

    Code (CSharp):
    1. myAgent.GetAgentProperty<bool>(FleeBehavior.fleeAttributeName);
    2.  
    I've attached a script you can use instead of Agent that will not rely on parenting, just be sure to call JoinNeighborhood(FlockBox flock).
     

    Attached Files:

  12. ntgCleaner

    ntgCleaner

    Joined:
    Jul 9, 2020
    Posts:
    27
    @check_marc That's a great idea, thank you! I will be doing that. I'm new to unity (though, not exactly new to C#) and I'm hoping to make a mindfulness game - I think this is the next trend in casual gaming. I'll absolutely try that, thank you!

    Thank you for this script! You went way out of your way to help me out here, I greatly appreciate it! I will put this in today and also will be giving you an awesome 5-star rating on the unity store. You've done some great work here and your support on this forum is awesome!
     
    mandisaw and check_marc like this.
  13. Dhagz

    Dhagz

    Joined:
    Aug 7, 2020
    Posts:
    2
    Hey I am just playing around with this, and it is really neat so far! I am very new to Unity, and using Playmaker, as I have no coding background. How can I make the player the leader or the target of a Seek? I see I can Tag my player as leader, or put him as a child of the flock box, but it does not seem to affect behavior of the Followers.
     
    check_marc likes this.
  14. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @Dhagz does your player object also have an Agent component?
     
    RomanDogStudios likes this.
  15. Dhagz

    Dhagz

    Joined:
    Aug 7, 2020
    Posts:
    2
    Hey thanks that works but now I can't control my player anymore! I will play around with it a bit, thank you for the tip.
    EDIT: Character is raised into the air when script agent is enabled. He will turn but not move. Disabling agent I can move, flock spins in spot with no leader, then follows again when script enables and I can't move again. I understand that something in my move controller will only allow me to move when i am touching the ground, and / or something in your agent script raises me into the air. If i raise the ground when script is on I can move again and it works wonderfully!
     
    Last edited: Aug 16, 2020
    check_marc likes this.
  16. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @Dhagz you may need to expand the size of the FlockBox. The only time Agent.cs will move the object is to snap it to the edge of the FlockBox when it is outside.
     
    Dhagz likes this.
  17. bodionafun

    bodionafun

    Joined:
    Aug 31, 2020
    Posts:
    1
    Hi, I am climbing the walls trying to use containment behaviour to add fish to a river. I have two issues that are driving me insane. Firstly the Flockbox is invisible so I have no way to check dimensions or allign it to my terrain. Secondly even if I do get it roughly in place which Ive managed at times, when I save and start the game it moves seemingly of its own volition. I'm 7 hours in! I am getting an error; Artifact meta info not present for hash 00d169d9ae741f5fc8f6772e2381ecc1. Any advice would be much appreciated. Thanks bodi.
     
  18. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @bodionafun There's a checkbox on the FlockBox component for "Draw Gizmos" under the Debug dropdown (you will also need Gizmos to be enabled in your Scene view). This will help you line it up with your environment.

    I would check for any physics components in its hierarchy that may be creating unexpected movement; there's nothing in FlockBox that will move the GameObject.

    I haven't seen that error before. If it's causing problems for you email me at marc(at)cloudfinegames.com and I can look into it.
     
  19. Octarina

    Octarina

    Joined:
    Oct 4, 2019
    Posts:
    8
    @check_marc Hi, I'm really interested by purchasing your asset.
    But I would like to check with you if there are any restriction with WebGL & IOS builds ?
     
  20. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @Octarina there are no such restrictions. This asset will work on any platform.
     
    Octarina likes this.
  21. swampmonster

    swampmonster

    Joined:
    Apr 14, 2020
    Posts:
    7
    like @Dhagz and @ntgCleaner , i am trying to have a user controlled gameobject that willinteract with the flockbox.
    i've tried putting the user controlled gameobject, with the agent script component added to it, inside the flockbox object and parented to it. This setup does not allow me to control the position of the object. Is this possible and if so how should it be setup?
     
  22. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @swampmonster are you able to drag the object around in the scene view while in Play mode?
     
  23. swampmonster

    swampmonster

    Joined:
    Apr 14, 2020
    Posts:
    7
    yes, i have it tagged as predator, and predator selected in the flee module in the behavior, but the boids don't seem to care.
     
  24. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @swampmonster if you're able to drag the player gameobject around in the scene, there may be an issue with whatever input control script you are using.

    To debug the flee behavior, I would start by cranking up the Weight and EffectiveRadius of the behavior, and enabling DrawDebugSteering to see if there's any visible result.
     
    swampmonster likes this.
  25. NiklasMoller

    NiklasMoller

    Joined:
    Dec 12, 2018
    Posts:
    6
    I’m planning to implement a scene where spiders climb up a skyscraper and into their windows. I made a purchase of this asset. How would you recommend me to go about this? I’m looking into the forager sample scene. Can I use something similar to create control points in order to control the flow up and into the skyscraper?

    Thanks!
     
  26. swampmonster

    swampmonster

    Joined:
    Apr 14, 2020
    Posts:
    7
    my lack of fleedom was caused by my optimized sleeping boids. once i turned their sleep off overything works.
    can't see the debug info at all, but at least the boids are responsive now.
     
  27. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @NiklasMoller I would start with 4 2D FlockBoxes based on the Forage Demo with one covering each face of the skyscraper. FlockBox isn't going to be able to navigate your spiders into the building, so you would need to take over with an animation when they approach a window. There's no waypoint system included, so you'll need to rely on Seek behaviors to draw them up the building.

    @swampmonster Are you able to see debug lines for other behaviors? If not, you may need to enable Gizmos in the Scene view.
     
    swampmonster likes this.
  28. k_dunlop

    k_dunlop

    Joined:
    May 10, 2019
    Posts:
    16
    Might be a silly question but like the fellow above I've been using the flock algorithms as a means to do wandering and pursuing zombie hordes (working well!) but I'm wondering; are any options to temporarily pause the behaviours once they've reached the target (the player), perhaps even pass a boolean within a certain radius so that I make switch to the zombies attacking or lurching state. Does such a routine exist or do we have to custom write one? Thanks! And good work on the asset, it was worth every penny.
     
  29. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @k_dunlop Glad you're having success with it! I would create a subclass of SteeringAgent for your zombies that checks distance to the player in Update() and uses SteeringAgent.LockPosition() to prevent movement.
     
  30. k_dunlop

    k_dunlop

    Joined:
    May 10, 2019
    Posts:
    16
    Thanks! I'll look into that.
     
  31. UnityZen

    UnityZen

    Joined:
    Jun 11, 2017
    Posts:
    2
    Do you recommend any method to use animator component and/or state machines for animating characters and animals that use Flock Box? I can't find anything mentioned in the doc or here, I would appreciate it if you could help me with this.
     
  32. Onat-H

    Onat-H

    Joined:
    Mar 11, 2015
    Posts:
    195
    Do you have any ETA for the ECS version?
     
    atomicjoe and DwinTeimlon like this.
  33. m-b-u-d-d

    m-b-u-d-d

    Joined:
    Jan 24, 2014
    Posts:
    1
    Are the agents able to have independent speeds and "foot prints"? For example, could there be a flock of soldiers and tanks moving together?
     
  34. guzz

    guzz

    Joined:
    Dec 16, 2012
    Posts:
    5
    do you have plan to add "flow field following" and "path following" behavior?
     
  35. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
    hi - I am liking FlockBox, seems like a very useful asset. However, the ExternalAgent script supplied above does not seem to work with the latest version of FlockBox? I am getting the following compilation errors:

    Assets\Plugins\FlockBox\Scripts\Core\SteeringAgents\ExternalAgent.cs(11,37): error CS0115: 'ExternalAgent.FindNeighborhood()': no suitable method found to override

    Assets\Plugins\FlockBox\Scripts\Core\SteeringAgents\ExternalAgent.cs(16,33): error CS0115: 'ExternalAgent.JoinNeighborhood(FlockBox)': no suitable method found to override

    can you help please?
     
  36. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    399
    hi all FYI I think I may have found a little bug in PhysicsSteeringAgent. Essentially, it needs a couple of additional transformations between flockbox coordinates and world coordinates if the flockbox is not aligned with the global axis, e.g. it has been rotated.
     
  37. xxluky

    xxluky

    Joined:
    Dec 4, 2014
    Posts:
    19
    Hi, as @UnityZen asked - I have a similar question. I want to make a bird with your Flock Box. I want to use animations. How can I know the states whether the bird is flying forward (for straight animation) or turning (to use turning animation) or going up or down (to use descending animation)??

    Thanks a lot for any tips.
     
    RomanDogStudios likes this.
  38. hzhou17

    hzhou17

    Joined:
    Aug 27, 2019
    Posts:
    2
    @check_marc I just bought the asset. Is there a way to control the leader (with mouse/keyboard/gamepad) in the follow_leader scene? I'm considering to make a game in which the player controls the leader.
     
  39. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @hzhou17 There is. Replace the SteeringAgent component with Agent and add whatever input scripts you need to move it.

    SteeringAgent will try to move the GameObject every frame but Agent will only be reactive to transform changes.
     
  40. AliYigitBireroglu

    AliYigitBireroglu

    Joined:
    Nov 20, 2015
    Posts:
    2
    @check_marc Hey, I recently purchased this asset for an underwater project that I am working on. It looks fantastic! I am still investigating the capabilities but so far I am very glad.

    Out of technical curiosity, I was wondering how did you achieve volumetric pathfinding? It seems like this asset can be used to control not only flocks but even individual elements like a plane or a robot flying inside a city. Am I wrong?

    Also, another question I have is, if a scene has more than one Flock Box with different objects assigned to each, will the boids in one box avoid the boids in another box while moving? In other words is it possible to have several small boxes all together in one scene instead of one big box?
     
    jorikito likes this.
  41. PixelKnights

    PixelKnights

    Joined:
    Feb 24, 2016
    Posts:
    15
    HI all,

    Really interested in this, can someone tell me please, does it use legacy animation system or mechanim and did it ever get updated to use ECS?

    Thanks
     
  42. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @AliYigitBireroglu There is no pathfinding exactly, just avoidance of immediate obstacles. They're purely reactive and do not form plans. If you have more than one Flock Box in a scene, the occupants of each will not be aware of each other. You can, however, have multiple populations inside of a single Flock Box that are directed to different places using the Seek behavior.
     
    AliYigitBireroglu likes this.
  43. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @PixelKnights There is no animations system, the SteeringAgent script will take control of the object's Transform. The DOTS implementation is still in development, but it's approaching an initial release.
     
    PixelKnights likes this.
  44. AliYigitBireroglu

    AliYigitBireroglu

    Joined:
    Nov 20, 2015
    Posts:
    2
    @check_marc Hi again! Thanks for the response. I have spent the last 2 weeks playing with Flock Box and its really great, thank you for this amazing work. It works wonderfully as it is but I have also been able to develop certain workarounds for some other things I wanted to do.
     
  45. lilacsky824

    lilacsky824

    Joined:
    May 19, 2018
    Posts:
    171
    Hi! I use your package to make schools of fish.
    Although collision is not work very well but still really cool.
    For performance problem I use a low resolution terrain mesh for collision currently.
     
  46. jeremedia

    jeremedia

    Joined:
    Apr 21, 2015
    Posts:
    63
    @check_marc I've been using Flock Box in my in-development VR project that targets the Oculus Quest. However, after updating to the new DOTS version the built app crashes on the headset during load. Once removing Flock Box and all of the DOTS-related packages the application launches normally.

    Have you been able to build the new version to Quest 1 or 2?
     
  47. check_marc

    check_marc

    Joined:
    Jan 26, 2013
    Posts:
    55
    @jeremedia I do have a test project that's working on Quest 2. Unity 2020.2.4f1 with FlockBox 2.0.1. I've had a lot of trouble with DOTS packages; they can be pretty unstable. If you're able to create a stable build with the DOTS packages but not FlockBox, please email me and I'll see what I can do.
     
  48. jeremedia

    jeremedia

    Joined:
    Apr 21, 2015
    Posts:
    63
    @check_marc thanks for the response. Knowing you have it working will motivate me to resolve the issue. Much appreciated.
     
  49. heathA

    heathA

    Joined:
    Aug 14, 2013
    Posts:
    4
    @check_marc Hi, does FlockBox work with URP? I downloaded and it is working as expected, but I'm also getting a lot of Unity crashes. I am not sure if it is the preview packages or something unrelated to your asset. I am using Unity 2020.3.7f1.
     
  50. jeremedia

    jeremedia

    Joined:
    Apr 21, 2015
    Posts:
    63
    @check_marc I've been unable to get the DOTS-enabled version of Flock Box to work in my Quest2-targeted VR project. I'm sure it's nothing specific to Flock Box, but some unfortunate combination of the preview packages and my project.

    I'd ask you to consider splitting the DOTS-enabled components into an optional package, enabling continued use of Flock Box by those in similar situations to mine.