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);
}