Search Unity

NavMesh.SamplePosition() not always returning closest point to sampled position

Discussion in 'Navigation' started by bagelbaker_legacy, Jun 12, 2015.

  1. We found a situation where NavMesh.SamplePosition() doesn't return the closest point to the sample position. In the attached picture, the sampled position is the red sphere and the result hit position is the white sphere.

    The expected result would be a point on the plane where the normal hits the red sphere. However, the actual returned result is always on the "internal edge" of the navmesh (white line on the blue navmesh). The bug only occurs near one of the horizontal white lines.

    In this test map, it only occurs if the plane slope is 45 degrees or more but in our game, we've seen it in smaller slopes.

    Reported bug case #702030. The reported bug was on Unity 5.0.2p2 but the issue is still there on Unity 5.1.0f3

    Anyone have any ideas about this?

    Actually, what would be the best way to get the the closest point on the navmesh below the sampled position, which is the position we're looking for, and not the closest point in 3D as is supposed to return NavMesh.SamplePosition()?
     

    Attached Files:

  2. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Was this ever solved? Having some similar issues in regards to SamplePosition.
     
  3. The bug case is still open and I never got any reply to it.
     
  4. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Ridiculous that no one has chimed in here. My biggest issue is that a NavMeshAgent itself can usually resolve these kinds of problems when I am not manually moving the character using SamplePosition. What in the hell is being done 'behind the scenes' to make it work properly then?
     
  5. MorningSir_LY

    MorningSir_LY

    Joined:
    Oct 26, 2017
    Posts:
    1
    upload_2018-5-16_16-52-48.png
    Like this, the red sphere is NavMesh.SamplePosition() returned position. I don't kown why ...
     
  6. GenOli

    GenOli

    Joined:
    Apr 21, 2013
    Posts:
    139
    Don't mean to necro but it might be something to do with the radius of the agent?
     
  7. michaelday008

    michaelday008

    Joined:
    Mar 29, 2019
    Posts:
    135
    Don't mean to necro, but I have this issue also.

    See the picture Attached.

    Here is the debug entry:
    ZombieUnit(Clone): CharacterMotor.FixedUpdate(): testPosition (361.5, 2.1, 319.4) on NavMesh found closest point: (361.5, -0.1, 319.4))

    So from the picture, Unit 3(zombie) is trying to follow Unit 1(player). Because you can't easily cut terrains in Unity, I've got one terrain 2 meters on top of another. The navmesh is baked onto both because the lower terrain pokes through the higher terrain elsewhere in this scene.

    Now as you can see from the picture, unit 1 is about 0.1 meters from the edge of the navmesh. However, as you can see from the debug entry above, when I ask it to sample the players position and find the closest point which should be about 0.1 meters away, it instead grabs some random point below the player at 2 meters away.

    This is not the "closest" position, so I think the description in the manual "Finds the closest point on NavMesh within specified range." is wrong. 2 meters away is not closer than 0.1 meters away...
     
  8. GenOli

    GenOli

    Joined:
    Apr 21, 2013
    Posts:
    139
    I got round this issue by making a custom navmesh by exporting the terrains as 3D models and merging them and making that only thing navmesh could use.
     
  9. chriscode

    chriscode

    Joined:
    Mar 2, 2015
    Posts:
    49
    I have something similar. SamplePosition returns a point on some terrain which is well below the convex mesh collider that the player is actually on!
     
  10. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Do you folks have a list of the known bugs in SamplePosition?