I am trying to develop a flocking algorithm but have stumped upon a technical issue. What I basicly do is when user activates a targetpoint a fix number of Gameobjects should start flying there.
What I do is have a Flockcontroller that takes the X amount of Gameobjects and tell them to start flocking behaviour. I appoint the one closes to the target as the leader. They will all get the list of flocking-objects so they can easily determine neighbours(without looking at ALL objects in the game).
So how do I go about doing the neighbour search(used when calculating cohesion and alignment)?
-
My first point was to have a spherecollider around all objects. I would then see if there is a Gameobjects inside, and reference that to the Flocking-list provided by the Flocking-controller. How do I determine if other objects are inside, is the only way to do OnTriggerEnter, add that to a list and then remove if OnTriggerExit, or can I (IsInsideMyCollider)?
-
My second option would be to raycast towards all possible neighbours. I would then measure the distance, and if they are withing Viewing-radius they would count as neighbours. Is this better?
The same method will also be applied for the separation part of the algorithm
One thing I also have trouble with is separation. I want the Gameobjects themselves to control as much as possible. Here I can not allow them to be proccessed one by one, because if the first Object moves, that would make the seconds objects calculation of the current Flockposition/Flockvelocity wrong. Instead I send a list of the necessary data to all Flocking-objects as it was in the beginning of the frame and then calculate as respect to this. Is this the way to go?
Ok I think that will have to do, thanks for reading!