public void OnPathComplete(Path p) { base.StartCoroutine(this.WaitToRepath()); if (p.error) { return; } this.path = p.vectorPath.ToArray(); float num = float.PositiveInfinity; int num2 = 0; for (int i = 0; i < this.path.Length - 1; i++) { float num3 = AstarMath.DistancePointSegmentStrict(this.path[i], this.path[i + 1], this.tr.position); if (num3 < num) { num2 = 0; num = num3; this.pathIndex = i + 1; } else if (num2 > 6) { break; } } }
public void OnPathComplete(Path p) { StartCoroutine(WaitToRepath()); //If the path didn't succeed, don't proceed if (p.error) { return; } //Get the calculated path as a Vector3 array path = p.vectorPath.ToArray(); //Find the segment in the path which is closest to the AI //If a closer segment hasn't been found in '6' iterations, break because it is unlikely to find any closer ones then float minDist = Mathf.Infinity; int notCloserHits = 0; for (int i = 0; i < path.Length - 1; i++) { float dist = AstarMath.DistancePointSegmentStrict(path[i], path[i + 1], tr.position); if (dist < minDist) { notCloserHits = 0; minDist = dist; pathIndex = i + 1; } else if (notCloserHits > 6) { break; } } }
public void InsertObstacleNeighbour(ObstacleVertex ob1, float rangeSq) { ObstacleVertex obstacleVertex = ob1.next; float num = AstarMath.DistancePointSegmentStrict(ob1.position, obstacleVertex.position, this.Position); if (num < rangeSq) { this.obstacles.Add(ob1); this.obstacleDists.Add(num); int num2 = this.obstacles.Count - 1; while (num2 != 0 && num < this.obstacleDists[num2 - 1]) { this.obstacles[num2] = this.obstacles[num2 - 1]; this.obstacleDists[num2] = this.obstacleDists[num2 - 1]; num2--; } this.obstacles[num2] = ob1; this.obstacleDists[num2] = num; } }
/*public void UpdateNeighbours () { * neighbours.Clear (); * float sqrDist = neighbourDistance*neighbourDistance; * for ( int i = 0; i < simulator.agents.Count; i++ ) { * float dist = (simulator.agents[i].position - position).sqrMagnitude; * if ( dist <= sqrDist ) { * neighbours.Add ( simulator.agents[i] ); * } * } * }*/ public void InsertObstacleNeighbour(ObstacleVertex ob1, float rangeSq) { ObstacleVertex ob2 = ob1.next; float dist = AstarMath.DistancePointSegmentStrict(ob1.position, ob2.position, Position); if (dist < rangeSq) { obstacles.Add(ob1); obstacleDists.Add(dist); int i = obstacles.Count - 1; while (i != 0 && dist < obstacleDists[i - 1]) { obstacles[i] = obstacles[i - 1]; obstacleDists[i] = obstacleDists[i - 1]; i--; } obstacles[i] = ob1; obstacleDists[i] = dist; } }