public Vector3 GetSteering(ICollection <AIMovement> targets) { Vector3 accel = Vector3.zero; int count = 0; foreach (AIMovement ai in targets) { if (steering.IsFacing(ai.Position, cosineValue)) { Vector3 a = ai.Velocity - rigbod.Velocity; a /= timeToDesiredSpeed; accel += a; count++; } } if (count > 0) { accel /= count; if (accel.magnitude > maxAcceleration) { accel = accel.normalized * maxAcceleration; } } return(accel); }
public Vector3 GetSteering(ICollection <AIMovement> targets) { Vector3 centerMass = Vector3.zero; int count = 0; // Sum of positions of AI in front of the current AI foreach (AIMovement AI in targets) { /* * Insures that only the positions of the AI in front of where the * current AI is facing are used in the calculation */ if (steering.IsFacing(AI.Position, cosineValue)) { centerMass += AI.Position; count++; } } if (count == 0) { return(Vector3.zero); } else { centerMass /= count; return(steering.Arrive(centerMass)); } }