Search Unity

SamplePosition Problem with NavMesh Seams/Edges

Discussion in 'Navigation' started by Multithreaded_Games, May 8, 2017.

  1. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Let me preface though by saying that I am trying to do something fairly unorthodox, which is to move my Rigidbody object using physics and then 'correct' the position with the sampled NavMesh position every frame. This gives me physics when I need it while forcing the character to be planted on the Navmesh. The NavMesh agent is not actually having its position/rotation updated and I'm updating its velocity with controller input (the same as is sent to the Rigidbody) Physics overhead is drastically reduced since a Navmesh mapping is (well, presumably) quicker than physics collisions.

    Either way, the point is that I have this VERY closely working. I've been using NavMesh.SamplePosition and it works 99.9% of the time. However, for whatever hellish reason, it gets 'stuck' on seams and I think that, in general, there is some underlying issue with these seams and there is some internal fudge that allows an positionally updated NavMesh to traverse them usually. I don't know how to describe this but I guarantee that there is something peculiar about these particular 'spots' where SamplePosition can't actually sample them, but instead returns an incorrect position, which locks the character 'closely' into place. As far as I can tell, NavMesh.Raycast has the same problem.

    These seams are entirely dependent on the geometry and I am positive that I am not the only one that has encountered these as I've seen them alluded to in other posts. On very rare occasions, I've seen actual kinematic NavAgents have difficulty traversing them at times as well. For instance, I cannot pass this confluence of weird lines as shown in this picture. When I am moving perpendicular towards the area enclosed by the box, the interior two lines that are closest together cannot be passed in the region in which the lines almost seem to converge.

    I've ruled out a few things: one, it doesn't seem to be a height-based discrepancy, as I'm able to traverse slopes and steps without issue (unless there are these seams.) It also doesn't occur when I am moving at a sufficiently high velocity (IE running.) This makes sense though, since the velocity vector's length while running extends beyond the 'seam', it's able to sample a position beyond the seam. Is it possible that SamplePosition can occasionally sample more than one 'closest' position at the same distance simultaneously and just 'picks' one?

    I've also tried FindClosestEdge, which actually only returns exterior edges, so no seams. I've also tried playing with building/clearing the height mesh, increasing the voxel size (which does help actually, but ultimately still results in seams, even when cranking it up way higher than I should.), different positional offsets, search radii size and area masks, and still cannot figure out a way to get the actual sampled position when moving over these problem areas.

    I could really use someone who has some in-depth knowledge of the NavMesh system to chime in here, because honestly, I'm at a complete loss. Thanks!
     

    Attached Files:

  2. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    I'm looking into this, while i'm doing that, could you try using a zero distance raycast as a workaround.
    so instead of SamplePosition - do :

    Code (csharp):
    1. // Kludge for SamplePosition seam problem
    2. NavMesh.Raycast (position, position out navMeshHit, -1);
    - ie. using sample position for start/end raycast ..
     
  3. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hi @Jakob_Unity,

    Thanks for your response! I've actually already tried this as well and I can confirm that the behavior is the same as if I had used NavMesh.SamplePosition, still getting stuck on seams.
     
  4. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    In that case i'd really like a repro. - would you plz submit one with the scene from your shapshot above - then report case # here or PM it to me.
     
  5. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    @Jakob_Unity

    Pared down the project a lot to create a much simpler test scene. Most of the important details are in the submission itself, but feel free to ask if anything is unclear. Here's the number: #911323.

    Thanks!
     
  6. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    @Jakob_Unity, I've received confirmation via e-mail that there does seem to be an issue with NavMesh.SamplePosition:

    "It turns out that the problem is indeed NavMesh.SamplePosition method.
    Anyway, I have sent this to the developers to fix."

    I'm sure you won't know this right off the top of your head, but do you have any idea when a fix can be expected for this problem? Is there a way I can keep up-to-date with the status of this bug or should I just check the Issue Tracker periodically?

    Thanks!
     
  7. Jakob_Unity

    Jakob_Unity

    Joined:
    Dec 25, 2011
    Posts:
    269
    Yes we're aware of an issue w. SamplePosition - which will be fixed.
    For now - since you have a NavMeshAgent i suggest using its API for constrained movement - e.g.:

    Code (csharp):
    1. // move to 'desiredPosition' but constrain the position to the navigation world
    2. agent.nextPosition = desiredPosition;
    3. // update the transforms position to the constrained position
    4. transform.position = agent.nextPosition;
    - hope that enables you to progress while i fix the SamplePosition issue.