UnityEngine.AI.NavMeshAgent.CalculatePath C# (CSharp) Method

CalculatePath() public method

Calculate a path to a specified point and store the resulting path.

public CalculatePath ( Vector3 targetPosition, NavMeshPath path ) : bool
targetPosition Vector3 The final position of the path requested.
path UnityEngine.NavMeshPath The resulting path.
return bool
        public bool CalculatePath(Vector3 targetPosition, NavMeshPath path)
        {
            path.ClearCorners();
            return this.CalculatePathInternal(targetPosition, path);
        }

Usage Example

Example #1
0
    NavMeshPath CalculatePath(Vector3 position)
    {
        Vector3     fleeDirection, newGoal;
        NavMeshPath path;

        fleeDirection = (this.transform.position - position).normalized;
        newGoal       = this.transform.position + fleeDirection * fleeRadius;
        path          = new NavMeshPath();
        _agent.CalculatePath(newGoal, path);
        while (path.status == NavMeshPathStatus.PathInvalid)
        {
            newGoal += fleeDirection;
            path     = new NavMeshPath();
            _agent.CalculatePath(newGoal, path);

            /*Debug.Log (newGoal);
             * Debug.Log (_xMin + " " + _xMax);
             * Debug.Log (_zMin + " " + _zMax);*/
            if (newGoal.x < _xMin || newGoal.x > _xMax)
            {
                Debug.Log(newGoal + " X:" + _xMin + " " + _xMax);
                Debug.Log((newGoal.x < _xMin) + " " + (newGoal.x > _xMax));
                return(null);
            }
            if (newGoal.z < _zMin || newGoal.z > _zMax)
            {
                Debug.Log((newGoal.z < _zMin) + " " + (newGoal.z > _zMax));
                Debug.Log(newGoal + " Z:" + _zMin + " " + _zMax);
                return(null);
            }
        }
        _agent.CalculatePath(newGoal, path);
        return(path);
    }
All Usage Examples Of UnityEngine.AI.NavMeshAgent::CalculatePath