public override Vector2 CalculateMove(Agent agent, List <Transform> context, FishFSM fish) { // No neighbours if (context.Count == 0) { return(Vector2.zero); } // Calcuate average between all neighbours Vector2 cohesionMove = Vector2.zero; // If filter is not null, use filtered context instead List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context); foreach (Transform item in filteredContext) { cohesionMove += (Vector2)item.position; } // Average position cohesionMove /= context.Count; // Create offset from agent position cohesionMove -= (Vector2)agent.transform.position; // Smooth movement cohesionMove = Vector2.SmoothDamp(agent.transform.up, cohesionMove, ref currentVelocity, agentSmoothTime); return(cohesionMove); }
public override Vector2 CalculateMove(Agent agent, List <Transform> context, FishFSM fish) { // Check size of behaviours and weights is equal if (weights.Length != behaviours.Length) { Debug.LogError("Data mismatch in " + name, this); return(Vector2.zero); } // Composite move Vector2 move = Vector2.zero; for (int i = 0; i < behaviours.Length; ++i) { Vector2 partialMove = behaviours[i].CalculateMove(agent, context, fish) * weights[i]; if (partialMove != Vector2.zero) { // Limit magnitudde of partial move to extent of weight if (partialMove.sqrMagnitude > weights[i] * weights[i]) { partialMove.Normalize(); partialMove *= weights[i]; } move += partialMove; } } return(move); }
public override Vector2 CalculateMove(Agent agent, List <Transform> context, FishFSM fish) { // No neighbours if (context.Count == 0) { return(Vector2.zero); } // Calcuate average between all neighbours Vector2 avoidanceMove = Vector2.zero; // Number of agents to avoid int nAvoid = 0; // If filter is not null, use filtered context instead List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context); foreach (Transform item in filteredContext) { if (Vector2.SqrMagnitude(item.position - agent.transform.position) < fish.SquareAvoidanceRadius) { nAvoid++; avoidanceMove += (Vector2)(agent.transform.position - item.position); } } // Average position if (nAvoid > 0) { avoidanceMove /= nAvoid; } return(avoidanceMove); }
public override Vector2 CalculateMove(Agent agent, List <Transform> context, FishFSM fish) { // No neighbours if (context.Count == 0) { return(agent.transform.up); } // Calcuate average between all neighbours Vector2 alignmentMove = Vector2.zero; // If filter is not null, use filtered context instead List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context); foreach (Transform item in filteredContext) { alignmentMove += (Vector2)item.transform.up; } // Average position alignmentMove /= context.Count; return(alignmentMove); }
void Start() { fishFsm = GetComponent <FishFSM>(); }
public void Initialize(FishFSM fish) { agentFish = fish; }
void Start() { fishFsm = GetComponent <FishFSM>(); fishWander = GetComponent <FishWander>(); _selfTrans = transform; }
public abstract Vector2 CalculateMove(Agent agent, List <Transform> context, FishFSM fish);