void OnDrawGizmosSelected() { if (path.waypoints != null && path.Size != 0) { path.DrawGizmos(); // Draw the arrival towards the last end point (if no looping) if (_bUsingArrive) { Arrive2D.DrawGizmos(Agent, arriveSensor); } // Show which current waypoint we are traveling to. else { Seek2D.DrawGizmos(path.CurrentWaypoint(), Agent); } } }
public override Vector2 SteerForce() { if (leader == null) { return(Vector2.zero); } // Convert the offset position into world coordinates. Vector2 worldOffset = leader.graphicTransform.TransformPoint(localOffset); Vector2 toOffset = worldOffset - (Vector2)Agent.transform.position; Vector2 leaderVelocity = leader.rigid.velocity; float lookAheadTime = toOffset.magnitude / (Agent.maxSpeed + leaderVelocity.magnitude); Vector2 futurePosition = worldOffset + leaderVelocity * lookAheadTime; arriveSensor.target = futurePosition; return(Arrive2D.SteerForce(Agent, arriveSensor)); }
public override Vector2 SteerForce() { // Invalid targets. if (!targetsAreValid()) { return(Vector2.zero); } Vector2 midpoint = (targetA.position + targetB.position) / 2f; float timeToReachMidpoint = Vector2.Distance(Agent.transform.position, midpoint) / Agent.maxSpeed; // Assume the targets will continue moving linearly in order to predict their future positions. Vector2 futurePositionA = targetA.position + targetA.velocity * timeToReachMidpoint; Vector2 futurePositionB = targetB.position + targetB.velocity * timeToReachMidpoint; Vector2 futureMidpoint = (futurePositionA + futurePositionB) / 2f; sensor.target = futureMidpoint; return(Arrive2D.SteerForce(Agent, sensor)); }
public override Vector2 SteerForce() { if (!evadeSensor.ShouldAvoid(Agent)) { arriveSensor.target = _lastHidingSpot; return(Arrive2D.SteerForce(Agent, arriveSensor)); } Vector2 hidingSpot = Vector2.zero; // Arrive at the hiding position. if (getNearestHidingSpot(ref hidingSpot)) { _lastHidingSpot = hidingSpot; arriveSensor.target = hidingSpot; return(Arrive2D.SteerForce(Agent, arriveSensor)); } // No hiding position available, evade target. else { return(Evade2D.SteerForce(Agent, evadeSensor)); } }