//void ApproachTarget /// <summary> /// Attempts to approach the target until it gets within range /// </summary> IEnumerator ApproachTargetRoutine(Transform target, float speed, float acceleration, float stoppingDistance, float angle) { // Store, then set the new settings var navSettings = new NavigationSettings(this.navigation); navSettings.Set(speed, acceleration, stoppingDistance); //Trace.Script("Will now approach " + target.name + " up until " + stoppingDistance + " units at " + speed + " speed!", this); this.OnMovementStarted(); // While we are not within range of the target, keep making paths to it while (Vector3.Distance(transform.position, target.position) > stoppingDistance) { //Trace.Script("Current distance = " + dist); this.MoveTo(target.transform.position); yield return(new WaitForFixedUpdate()); } //Trace.Script("Approached " + target.name, this); // Now that we are in range of the target, let's revert to the old settings and stop moving this.navigation.isStopped = true; navSettings.Revert(); this.steeringRoutine = null; this.OnMovementEnded(); }
//protected void FollowPath(Vector3[] points, float speed, float acceleration, float stoppingDistance) //{ // if (CurrentRoutine != null) StopCoroutine(CurrentRoutine); // CurrentRoutine = FollowPathRoutine(points, speed, acceleration, stoppingDistance); // StartCoroutine(CurrentRoutine); //} /// <summary> /// Moves this agent through a list of points. /// </summary> protected IEnumerator FollowPathRoutine(Vector3[] points, float speed, float acceleration, float stoppingDistance) { // Store, then set the new settings var navSettings = new NavigationSettings(this.navigation); navSettings.Set(speed, acceleration, stoppingDistance); this.OnMovementStarted(); // Create a new line renderer to draw this path //PathDisplay pathDisplay; //if (this.IsDebugging) //{ // pathDisplay = new PathDisplay(this.gameObject, points, Color.red, Color.blue); //} IEnumerator drawRoutine = null; if (this.debug) { drawRoutine = DrawPathRoutine(points, Color.red, Color.yellow); StartCoroutine(drawRoutine); } // Now travel the path foreach (var point in points) { Trace.Script("Moving to next point: " + point, this); while (Vector3.Distance(transform.position, point) > stoppingDistance) { this.navigation.SetDestination(point); yield return(new WaitForFixedUpdate()); } } Trace.Script("Finished the path!"); if (this.debug) { StopCoroutine(drawRoutine); } this.OnMovementEnded(); this.navigation.isStopped = true; navSettings.Revert(); }
/// <summary> /// Moves this agent through a list of points. /// </summary> protected IEnumerator FollowPathRoutine(Vector3[] points, float speed, float acceleration, float stoppingDistance) { // Store, then set the new settings var navSettings = new NavigationSettings(this.navigation); navSettings.Set(speed, acceleration, stoppingDistance); this.OnAgentMovementStarted(); IEnumerator drawRoutine = null; if (this.debug) { drawRoutine = DrawPathRoutine(points, Color.red, Color.yellow); StartCoroutine(drawRoutine); } // Now travel the path foreach (var point in points) { StratusDebug.Log("Moving to next point: " + point, this); while (Vector3.Distance(transform.position, point) > stoppingDistance) { this.navigation.SetDestination(point); yield return(new WaitForFixedUpdate()); } } StratusDebug.Log("Finished the path!"); if (this.debug) { StopCoroutine(drawRoutine); } this.OnAgentMovementEnded(); this.navigation.isStopped = true; navSettings.Revert(); }