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)); } }
public Vector3 GetSteering(AIMovement target, Vector3 offset, out Vector3 targetPos) { var offsetPos = target.Position + target.Transform.TransformDirection(offset); // Calculates the distance to the specified point away from the target var dist = offsetPos - transform.position; var distance = dist.magnitude; var speed = rigbod.Velocity.magnitude; float prediction; if (speed <= distance / maxPrediction) { prediction = maxPrediction; } else { prediction = distance / speed; } targetPos = offsetPos + target.Velocity * prediction; return(steering.Arrive(targetPos)); }
void FixedUpdate() { // Calls to the Steering script for the arrive function. Vector3 accel = steering.Arrive(targetPosition); steering.Steer(accel); steering.LookWhereGoing(); }