示例#1
0
        public void InsertObstacleNeighbour(ObstacleVertex ob1, float rangeSq)
        {
            ObstacleVertex ob2 = ob1.next;

            float dist = Mathfx.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;
            }
        }
示例#2
0
    /** Called when a path has completed it's calculation */
    public void OnPathComplete(Path p)
    {
        /*if (Time.time-lastPathSearch >= repathRate) {
         *      Repath ();
         * } else {*/
        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 = Mathfx.DistancePointSegmentStrict(path[i], path[i + 1], tr.position);
            if (dist < minDist)
            {
                notCloserHits = 0;
                minDist       = dist;
                pathIndex     = i + 1;
            }
            else if (notCloserHits > 6)
            {
                break;
            }
        }
    }