Flocking with flee and pursue

Hi i am making an underwater survival game with sharks and fish (no humans) I am using mercuna (no navmesh is being used). I am also using behavour designer. I am using the flocking from this video. It is working fine but what i am now trying to achieve is to get the fish to flee from shark objects and for sharks to be able to pursue(chase and attack) the flock of fish but i am not sure how to do this if anyone could help please ?

Well, if you implemented above (nice) tutorial on flock behaviour. have the group manager detect the shark (by proximity), have all fish increase their speed, and pick a new flock point, far awa and at right angles to the current shark’s heading. That should simulate the whole swarm fleeing from the shark. Have the shark continue to follow its intended pre, but make it lose its prey by a certain chanche each update.

ah right how would i go about implementing this in my script as the tutorial dosen’t seem to cover this? and also the shark dosen’t detect the fish to pursue either?

You probably want something like that.

yeah exactly like that :slight_smile: but not sure how do this?

For similar effect, you best bet is to study DOTS / ECS.
This example uses boids algorithm for school of fish.
Source link is in the video description.

But you can scale down problem, and get just boids algorithm and do similar in classic OOP, with Game Objects.You still could have few thousands of fish. Jobs System may help as well, as an alternative to ECS / DOTS.

ah right i looked at the scripts but and tested one but it just has errors come up. would i need a new script or can i add to my flock and flock manager script?

It may not be that straight forward as just copy, since demo is using DOTS.
But is possible to rewrite it to OOP. Or perhaps find some existing project with boid / school of fish for OOP.

Regarding demo, you should use Unity 2019.x and load whole project.

What error you get?

directive assembly references for write group local to world and a few others? this if for that boid script

Which Unity you have installed, and which entity and burst preview you got installed?

Mind, you can not just copy single script from github ECS samples. It won’t work like that.
You need load whole project, if you not sure what is going on yet.

ah i thought i have the latest one but it turns out i haven’t :frowning: is their an older version for unity 2018?

Was, but was upgraded.
Still, need open full boids project, not just copy a script.

ah right so download it then integrate it ?

Please make sure, you read instruction below, before stepping in,

More less. But that probably won’t straight forward, if you are not familiar with ECS / DOTS. So you will need to take a time, to dive into that topic. If that what you want. Otherwise, you may get trouble to get things working.

Maybe you can manage extract boids algorithm, if you have decent C# background.

just going to have a look at the read me now :slight_smile: do i need any other program accept unity?

No. Just need relevant package from Package Manager.
But if you open Project in 2019.1, you should have all ready there.

have all the packages in my manager on the read me list