I am working on a 2D game in flocking based XNA. I implemented the Craig Reynold flocking technique, and now I want to dynamically assign a leader to the group in order to guide it toward the goal.
To do this, I want to find a game agent who has no other agents in front of him and make him a leader, but I'm not sure about the math for this.
I currently have:
Vector2 separation = agentContext.Entity.Position - otherAgent.Entity.Position; float angleToAgent = (float) Math.Atan2(separation.Y, separation.X); float angleDifference = Math.Abs(agentContext.Entity.Rotation - angleToAgent); bool isVisible = angleDifference >= 0 && angleDifference <= agentContext.ViewAngle;
agentContext.ViewAngle - these are the values โโof the radians that I played with in order to try to get the right effect, but this basically leads to the fact that all agents are appointed leaders.
Can someone point me in the right direction to determine if the object is in the โconeโ of the vision of another object?
Jason source share