Search Unity

Discussion Navmesh Calculate path not ignoring obstacles

Discussion in 'Navigation' started by JacobDecisionLab, Feb 9, 2023.

  1. JacobDecisionLab

    JacobDecisionLab

    Joined:
    Nov 16, 2022
    Posts:
    9
    Hi,

    I have been doing a lot of googling to find solutions to my problem but not seem to take into account navmesh obstacles. I am trying to use the NavMesh.CalculatePath() function to get the path that would be traversed between point A and point B. (Note: my agent is not at either point)

    Code (CSharp):
    1. NavMeshPath path = new NavMeshPath();
    2. path.ClearCorners();
    3. NavMesh.CalculatePath(pointA.transform.position, pointB.transform.position, agent.areaMask, path);
    When I do this, however, the path that it finds goes directly through obstacles as if they are not there.

    When I use other Calculate path functions from the agents current location or simply when the agent is traversing the terrain, the obstacles are taken into account as expected.
     
  2. JacobDecisionLab

    JacobDecisionLab

    Joined:
    Nov 16, 2022
    Posts:
    9
    Found the issue. It was because the calculation i was doing was occurring at zero time (i.e before the navmesh had even had time to process the carving of the obstacles)