I'm working on a 2D game in XNA based around flocking. I've implemented Craig Reynold's flocking technique and now I want to dynamically assign a leader to the group to guide it towards a target.
To do this, I want to find a game agent that does not have any other agents in front of it and make it the leader but I'm unsure of the maths for this.
Currently I 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 is a radians values which I have played with to try and get the right effect but this mostly results in all agents being assigned as leaders.
Can anyone point me in the right direction to detect if an entity is within a "cone" of view of another entity?