public static Vector3 Evade(SteeringActor actor, SteeringActor pursuer) { SteeringBehaviours.Forces attributes = actor.GetAttributes().Forces; Vector3 toPursuer = pursuer.GetPosition() - actor.GetPosition(); float lookAhreadTime = toPursuer.magnitude / (attributes.MaxSpeed + pursuer.GetVelocity().magnitude); return Flee(actor, pursuer.GetPosition() + (Vector3)pursuer.GetVelocity() * lookAhreadTime); }
public static float GetObstactleAvoidanceLookAheadDist(SteeringActor actor) { return 1.0f + actor.GetVelocity().magnitude * 2.0f; }
public static Vector3 Pursuit(SteeringActor actor, SteeringActor evader) { SteeringBehaviours.Forces attributes = actor.GetAttributes().Forces; Vector3 toEvader = evader.GetPosition() - actor.GetPosition(); Vector3 thisHeading = actor.GetVelocity(); thisHeading.Normalize(); Vector3 evaderHeading = evader.GetVelocity(); evaderHeading.Normalize(); float relativeHeading = Vector3.Dot(thisHeading, evaderHeading); float tresholdAngleAcos = Mathf.Acos(attributes.PursuitThresholdAngle); if (Vector3.Dot(toEvader, thisHeading) > 0 && (relativeHeading < -tresholdAngleAcos)) { return Seek(actor, evader.GetPosition()); } // the look ahead time is proportional to the distance between the evader // and the pursuer; and is inversely proportional to the sum of the agents velocities float lookAheadTime = toEvader.magnitude / (attributes.MaxSpeed + evader.GetVelocity().magnitude); // Now seek to the predicted future position of the evader return Seek(actor, evader.GetPosition() + (Vector3) evader.GetVelocity() * lookAheadTime); }