示例#1
0
    /** Requests a path to the target.
     * Bypasses 'is-it-a-good-time-to-request-a-path' checks.
     */
    public virtual void ForceSearchPath()
    {
        if (target == null)
        {
            throw new System.InvalidOperationException("Target is null");
        }

        lastRepath = Time.time;
        // This is where we should search to
        var targetPosition  = target.position;
        var currentPosition = GetFeetPosition();

        // If we are following a path, start searching from the node we will
        // reach next this can prevent odd turns right at the start of the path
        if (interpolator.valid)
        {
            var prevDist = interpolator.distance;
            // Move to the end of the current segment
            interpolator.MoveToSegment(interpolator.segmentIndex, 1);
            currentPosition = interpolator.position;
            // Move back to the original position
            interpolator.distance = prevDist;
        }

        canSearchAgain = false;

        // Alternative way of requesting the path
        //ABPath p = ABPath.Construct (currentPosition,targetPoint,null);
        //seeker.StartPath (p);

        // We should search from the current position
        seeker.StartPath(currentPosition, targetPosition);
    }