Search Unity

Question NavMeshAgent.SamplePathPosition and NavMesh.SamplePoint NavHit.mask Always 1

Discussion in 'Navigation' started by darkwingfart, Sep 3, 2021.

  1. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    78
    I'm trying to make my agents get out of the street after entering it. I have a grid I'm testing on with random stops on the OffMeshLinks.
    upload_2021-9-3_4-12-55.png

    When an agent moves from the areas with the Objectives (blue) to the street (purple) I want them to ignore the stop request on the NavMeshLink by sampling the area they are in. Here is my check. The "here" debug log never fires, the navHit.mask always equals 1.

    Code (CSharp):
    1. if (OffMeshLink || Agent.isOnOffMeshLink) {
    2.                 OffMeshLink = true;
    3.                 OffMeshLinkName = Agent.currentOffMeshLinkData.offMeshLink.gameObject.transform.parent.parent.name;
    4.                 NavMeshHit navHit;
    5.                 if (!Agent.SamplePathPosition(NavMesh.AllAreas, 1F, out navHit)) {
    6.                     Debug.DrawRay(navHit.position, Vector3.up, Color.blue, 1.0f);
    7.                     Debug.Log(navHit.mask);
    8.                     int streetMask = 1 << NavMesh.GetAreaFromName("Street");
    9.                     if ((navHit.mask & streetMask) != 0) {
    10.                         Debug.Log("here");
    11.                     }
    12.                 }
    13.              
    14.                 if (navHit.mask == 8 || OffMeshLinkName == "go") {
    15.                     OffMeshLink = false;
    16.                     OffMeshLinkName = "";
    17.                     Agent.CompleteOffMeshLink();
    18.                 }
    19.             }
     
  2. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    78
    Here is my area mask definition.
    upload_2021-9-3_4-18-27.png
     
  3. darkwingfart

    darkwingfart

    Joined:
    Oct 13, 2018
    Posts:
    78
    I had to make the OffMeshLinks unidirecitonal and mark them as Street or Walkable for this to work.

    This means I have twice as many OffMeshLinks as I did before.

    The behavior of NavMeshAgent.SamplePathPosition and NavMesh.SamplePoint is unreliable and basically unusable.