Search Unity

Bug Navmesh path only returns 2 corners (start + end point)

Discussion in 'Navigation' started by unitydev112, Dec 14, 2022.

  1. unitydev112

    unitydev112

    Joined:
    May 29, 2019
    Posts:
    14
    No matter what, my Navmesh path only shows me 2 corners but the agents walks as expected (in a "zig zag environment" avoiding obstacles, turning, ...)
    Based on Unity docs
    I'd expect at least 6 waypoints in my scenario,
    "Also known as "waypoints", the corners define the places along a path where it changes direction (ie, the path consists of a number of straight-line moves between corners)."

    Code (CSharp):
    1.         NavMeshPath path = new NavMeshPath();
    2.         Vector3 p1 = agentStartPosition.position;
    3.         Vector3 p2 = target.position;
    4.         NavMesh.SamplePosition(p1, out NavMeshHit hit, 10, NavMesh.AllAreas);
    5.         p1 = hit.position;
    6.         NavMesh.SamplePosition(p2, out hit, 10, NavMesh.AllAreas);
    7.         p2 = hit.position;
    8.         NavMesh.CalculatePath(p1,p2, NavMesh.AllAreas, path);
    9.         Debug.Log(corners.Length);
    10.  
    11. //trying to calculate from the agent
    12.         agent.CalculatePath(p2, path);
    13. Debug.Log(corners.Length);
    14.  
    15.         agent.SetDestination(p2);
    16.  
    17.        
    I want to calculate a path from a start to an end position and set waypoints/checkpoints on the path.

    So what could I do?

    Thanks!!!
     
  2. unitydev112

    unitydev112

    Joined:
    May 29, 2019
    Posts:
    14
    Wow...., after posting here I found that my Navmesh Obstacles had "carve = false" so that was the problem...

    still curious, why could the agent walk properly? (because the calculated path was of course only a straight line...)