Updating toSeparateFromAgents at runtime?

For testing I am creating a flock of Critters (a subclass of GKAgents) in a loop, each critter has 3 goals:


  1. Seek (Weighted at 0.05)
  2. Wander (weighted at 1.0, but disabled as I can't get it to work)
  3. Seperate (Weighted at 10.0)


As I create each Critter I add them to my flock, what I am puzzled by is the way that goals (like seperate) that require an array of agents work at runtime. When I create each Critter (and its seperate goal) and add them to my flock this is what I will get


  1. Critter_001 - flock[]
  2. Critter_002 - flock[Critter_001]
  3. Critter_003 - flock[Critter_001, Critter_002]
  4. Critter_004 - flock[Critter_001, Critter_002, Critter_003]
  5. Finally arriving at - flock[Critter_001, Critter_002, Critter_003, Critter_004]


As you can appreciate if this list is taken as-is at creation than Critter_001 has no one to seperate from and Critter_002 only seperates from Critter_001. I would hope that on each cycle of the update loop the goals look at the current state of the flock. If this is not the case then it could be very limiting as the entire flock would have to be setup initially (before any goals) as the first Critter into the flock needs to know about the last. It would also mean that killing off Critters would potentially slow things down as other Critters could be trying to look for / avoid flock mates that no longer exist.


Does anyone know, or have they spotted anything in the docs / examples that explains how this works.


EDIT: I am pretty sure now that the list of GKAgents in the flock is set when you actually create the goal and can't be modified later by adding to the array. If you look at the image below you will see that the other agents show some notion of adjusting their paths to seperate from other flock members. Critter_001 on the other hand defaults to a circular orbit of the goal as he is blissfully unaware of any of his flock buddies ... sad really 😟


https://goo.gl/photos/dpWzBbwdDzHzNK5o6



OK so how do you get picture to show, it shows above in the edit, but is gone when I view after pressing [Post]? *** Ye olde link added instead.

I solved the problem above by first creating all the critters without any behavors and adding them to a flock. Once the entire flock had been created I looped through each flock member and assigned behavors. This way all the Critters had a list of their fellow flock buddies right from the start.

+1


I am also puzzled by this when using the avoid behavior.


In my example I need to update an enemy goal to avoid any projectile fired by a player. When an enemy is spawned there are no projectiles yet. Once the player fires a projectile the avoidance goal of an enemy needs to be updated with the projectiles headed their way. How and when should I do this? Right now I can only recreate a new goal although this doesn't seem to work. I do not have the luxury to know how many projectiles there will be in advance.


Update:

In case anyone stumbles upon this post and wonders if I managed to fix it. My solution is as follows:

Every second I update an array with GKAgent objects representing the projectiles. Along with that array a GKGoal (avoid) is shared among all "Enemy" objects and updated.

Updating toSeparateFromAgents at runtime?
 
 
Q