Simulating a bait ball (flocking)

Started by
10 comments, last by Masri 16 years, 6 months ago
Hello all, I'm currently in the middle of trying to simulate a bait ball (As Seen On TV!). For those that don't know it's basically a situation in the ocean where a large shoal of fish becomes sorrounded by predators and they get stuck in this very large heaving ball with the predators coming in and attacking the sides of the ball. I've started with just the basic flocking algorithm (slightly modified) Rule #1 Keep correct distance from nearest neighbour. This is done with zones, an attraction zone, a neutral zone and a repulsion zone. Rule #2 Turn to heading of Nearest Neighbour Rule #3 Turn to centre of flock Rule #4 Turn to destination of flock (this is to give the shoal some sense of direction and is changed every 20-30 seconds). That all worked well for general roaming and i figured that when a shoal is under threat they follow the same rules but the zones are much tighter (making the shoal tighter), the speed is increased and they ignore the destination. Except it's too chaotic, it looked more like there were feeding on some even smaller invisible fish than under threat. They were zipping into the centre of the flock and away again. Which is cool in itself but not what i'm after. So now i'm thinking that i won't be able to do this using one general flocking algorithm, i'll have to have an "under threat"(for the prey) and "attacking"(for the predators) states with different rules. Under threat: Rule #1 the same but tighter zones. Rule #2 the same. Rule #3 Keep correct distance to centre of flock (again using 3 zones) Rule #4 Turn to heading perpendicular to centre of flock (hopefully this should keep them circling the center rather than diving into it) Rule #5 avoid predators. Attacking: I haven't quite figured out the rules for this yet, i want to get the bait ball right first. I'm not too happy about having all these states and different rules and i'm pretty sure these rules will mean they will always go into a bait ball when under threat, even if there is only one predator around which won't be great. Perhaps rule 4 is not needed and the circling will naturally happen while avoiding predators from all sides... Anyway, now i'm just writing as i'm thinking so i better stop. I was just wandering if anybody had tried anything similar, or if anybody had any suggestions? Cheers. hmm, the two states are similar... parhaps if I change rule #3 in the general state with rule#3 in the under threat state and add rule #5 that'll work...
Without the 0, alot of bigger numbers would just stand around feeling rather silly.
Advertisement
I haven't done this but I agree you'll need a bit more logic than just steering. I'd have a set of emotions as fuzzy variables that you use to select which rule to apply.

For example, the sharks would have a "desperateness" emotion that would increase over time, and would trigger an attack after a while. After an attack, it would go down to zero and the shark would start circling again...

Sounds cool though, do you have any screenshots?

Join us in Vienna for the nucl.ai Conference 2015, on July 20-22... Don't miss it!

I would think that you could pull this off without the states. If you were simply using a predator as another input vector, then it becomes its own state. If there isn't a predator nearby then there is no vector change. If the predator gets close, it starts getting factored in.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

The predators surrounding the fish is an important factor here. Predators intentionally do this to make it easier to catch the fish. I think the fish just need to move away from predators (while still being influenced by the other rules). It's the predators that must be given the herding behavior.
That's a good point - however, predators have learned what "herding behavior" is because of certain observations of the behavior of the prey. If the behaviors of the prey are not modeled correctly, it is impossible to model the behaviors of the predators since they will be working from an incorrect premise. You are right, however. You can't just simply put in a switch that says "if predators are nearby, make a ball".

Unless of course, you are looking for something simplistic as an EFFECT rather than trying to model the actual behavior. It sounds like you are doing the simulation, not the effect.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Thanks for the replies.

I don't have any screenshots at the moment because i'm on a different computer.

I think you're right about not modelling the fish to go into a ball but rely on the avoidance of the predators to do this for me.

It does however mean i have to get both the behaviours pretty much spot on to get the desired effect, lots of trial and error me thinks!

If it still fails after that i may just force the fish into a ball just to see what it would look right but you're right, IF, i am really more going for a simulation rather than just the effect.

Cheers.
Without the 0, alot of bigger numbers would just stand around feeling rather silly.
It all sounds fairly good, but yes... I agree with the others about the predator behaviour being key.

Generally, I think in that situation the fish arent actively trying to form a ball, but in fact form a ball despite their efforts.
The fish will usually try to escape and move away from the ball, toward whatever cover / open water / whatever they use for their defense mechanism, but are actively herded into the ball by the predator. For the purposes of your algorithm, Id suggest that this is equal to having a flock destination that points wherever the predators' ring is weakest, with the general effect in nature is that they attempt to get to that weak point but the predators are too fast and close that gap, and the fish choose another weak point instead.


One question I have is, what exactly do you mean by "making the zones tighter"? Do you mean you are decreasing the area-of-effect for the repulsion effect, so that the fish group more tightly?
In nature, Id say that that isnt really what happens... rather the closeness is, again, in spite of their efforts rather than because of them. It is the predators pushing them so that the fish dont have enough room to stay out of each others' space.


Your basic algorithm sounds pretty good, to me... As you've said, it works well for general roaming.

My suggestion would be to leave that behaviour as unchanged as possible, but rework your predator repulsion zones.

eg - Try setting up a solid ring or sphere with a really strong repulsion (strong enough to 1: Force the fish into a confined space and partly overcome the fishes' own repulsion zones, and 2: overcome their destination turning and keep the fish from breaking out of the ring).
Then, simulate weak points by randomly setting a destination point outside of the ring, and changing that point when the fish get too close to the ring.

To do it with predators you would have roughly the same setup, but instead of a solid ring, the predators would be attempting to move in such a way as to create the best ring that they can, and the weak-points would occur naturally. Doing it with a solid ring first just makes it easier than having to tweak both the fish and predator zone strengths at the same time.
Just thought of something - although it will be a bitch to implement. One of the reasons that fish will consent to moving into the ball rather than out of the ring through any gap that they can is that they don't know they are in a ring. They only see the predator on their side. They are banging into the bait ball saying (in a fishy voice) "why won't you guys move! Can't you see there's a shark over here?" As far as their perception goes, they are moving in the right direction - i.e. away from the perceived threat.

In order to model this, you would have to have each prey agent ignore the predator on the other side of the ball - negating that predator's repulsion zone therefore making it look like the vector through the ball is the safe way to go. How do you model that without a ton of LOS checks?

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Oh... another point. Some fish may believe in the falacious premise of "safety in numbers". To model this, you really need to pump up the "pull" of the group in addition to the push of the predators. Translated, even if they see a path between two predators, they may ignore it in favor of the ball. Probably your cohesion factor would be the way to go. It would guarantee the formation of the group.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

If a fish sees that it is going on a path that leads between two predators, I think its first instinct would be to change direction as quickly as possible, regardless of its school.

The way I see it, each fish is only influenced by what it can sense. Things that are closer and/or larger tend to be easier to see, while things a relatively short distance further away might barely be sensed or not sensed at all because of camoflage. Fish are also probablyt sensitive to the small currents created by the other fish around them, which could give them a good idea of where the school is going.

So...my influences on the steering would be:
1. Direction that closest neighbors in front of fish are swimming (fairly constant influence)
2. Direction that points towards closest neighbors (quickly becomes stronger as the distance to the neighbors increases)
3. Avoid collisions with neighbors in front by slowing down and possibly by also steering away from the school (quickly becomes stronger as the fish approaches the neighbor in front of it, this shouldn't be too important if the fish all swim at the same speed anyway)
4. Move towards goal (very weak, so it just affects the fish that don't have neighbors in front of them or any other influences)
5. Run away from predators

A simple way to simulate the predators might be to have them going in a circle of a fixed radius around the approximate center of the school. The influence of the predators on the fish, the speed at which predators circle, and the number of predators could be adjusted. In fact, a simple steering behavior for the predators could be just trying to stay on their goal position in a circle that is spinning around the fish.

This topic is closed to new replies.

Advertisement