Steered Cohesion behaviour for boid model is making all my agents head towards origin (0,0)
When I start my game all my boids head towards origin, however this doesnt occur when i set the weighting of my steered cohesion behaviour to 0. which leads me to believe the error lies somewhere in this script.
public class SteeredCohesionBehaviour : FilterFlockBehaviour
{
Vector2 currentVelocity;
public float agentSmoothTime = 0.5f;
public override Vector2 calculateMove(FlockAgent agent, List<Transform> context, Flock flock)
{
//if no neighbours return no adjustment
if (context.Count == 0)
{
return Vector2.zero;
}
//add all points together and average
Vector2 cohesionMove = Vector2.zero;
List<Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);
foreach (Transform item in filteredContext)
{
cohesionMove += (Vector2)item.position;
}
cohesionMove /= context.Count;
//create offset from agent position
cohesionMove -= (Vector2)agent.transform.position;
cohesionMove = Vector2.SmoothDamp(agent.transform.up, cohesionMove, ref currentVelocity, agentSmoothTime);
return cohesionMove;
}
}
for my boid model i followed this guide
any help would be greatly appreciated, thank you
Comment
Your answer
Follow this Question
Related Questions
Destroying enemy only partially works 0 Answers
Trying to draw a line between two randomly generated point 0 Answers
How can i decrease lives? 0 Answers
Box Collider Blocks Movement,Box Collider Blocks movement after collision 0 Answers
Trying to Invoke method: Character_ControllerXD.SuperSpeedJump couldn't be called. 0 Answers