public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock) { if (weights.Length != behaviors.Length) { Debug.LogError("Array length mismatch in " + name, this); return(Vector3.zero); } Vector3 move = Vector3.zero; Vector3 partialMove; for (int i = 0; i < behaviors.Length; i++) { partialMove = behaviors[i].CalculateMove(plane, context, flock) * weights[i]; if (partialMove != Vector3.zero) { if (partialMove.sqrMagnitude > weights[i] * weights[i]) { partialMove.Normalize(); partialMove *= weights[i]; } move += partialMove; } } return(move); }
public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock) { Vector3 centerOffset = center - plane.transform.position; float t = centerOffset.magnitude / radius; if (t < 0.9f) { return(Vector3.zero); } return(centerOffset * t * t); }
private List <Transform> getNearbyObject(planeBehavior agent) { List <Transform> context = new List <Transform>(); Collider[] contextcolliders = Physics.OverlapSphere(agent.transform.position, NeighborRadius); foreach (var collider in contextcolliders) { if (collider != agent._Collider) { context.Add(collider.transform); } } return(context); }
public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock) { if (context.Count == 0) { return(Vector3.zero); } Vector3 AlignMove = plane.transform.forward; foreach (var transform in context) { AlignMove += transform.forward; } AlignMove /= context.Count; AlignMove = Vector3.SmoothDamp(plane.transform.forward, AlignMove, ref currentVelocity, 0.3f); return(AlignMove); }
public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock) { if (context.Count == 0) { return(Vector3.zero); } Vector3 cohesionMove = Vector3.zero; foreach (var transform in context) { cohesionMove += transform.position; } cohesionMove /= context.Count; cohesionMove -= plane.transform.position; cohesionMove = Vector3.SmoothDamp(plane.transform.forward, cohesionMove, ref currentVelocity, agentSmoothTime); return(cohesionMove); }
public override Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock) { if (context.Count == 0) { return(Vector3.zero); } Vector3 AvoidMove = Vector3.zero; int nAvoid = 0; foreach (var transform in context) { if (Vector3.SqrMagnitude(transform.position - plane.transform.position) < flock.SquareAvoidanceRadius) { nAvoid++; AvoidMove += plane.transform.position - transform.position; } } if (nAvoid > 0) { AvoidMove /= nAvoid; } return(AvoidMove); }
public void RemoveAgent(planeBehavior agent) { agents.Remove(agent); }
public void AddAgent(planeBehavior agent) { agents.Add(agent); }
public abstract Vector3 CalculateMove(planeBehavior plane, List <Transform> context, Flock flock);