Search Unity

NavMeshSurface HeightMap

Discussion in 'Navigation' started by Multithreaded_Games, Aug 31, 2017.

  1. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hi all,

    Using the new navigation components with Unity 2017... just curious if there are any plans to allow Heightmap baking anytime soon--I see that the checkbox is grayed out and the documentation says "Not supported." Without this, it seems that the character hovers quite a bit off the ground--I assume I could fix this by messing with the base offset, but I'm still curious about the height map. Thanks!
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    You can change the voxelsize in the NavmeshBuildSettings (smaller voxel size improves the quality of the navmesh). This will create a much better navmesh, but unfortunatley your baking will take much longer as well.
     
    Multithreaded_Games likes this.
  3. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Thanks for the response! I figured this out already--unfortunately, it seems like you have to use the same voxel size parameter for each entity (I have several of varying radii) to get good results. Since this is dependent on the radius, it seems that larger entities simply require more 'voxels per radius' and thus take longer to build. Either way, this will work for now.

    While messing around with this, I did come across odd behavior--specifically, why does a larger built radius place the character higher and higher off the ground? I would think that the radius has nothing to do with the height offset. You can test this easily by building multiple navmeshes on a flat surface and see that they form 'layers' where the ones with higher radii are further from the surface on which they are built. Odd...
     
  4. rcabot

    rcabot

    Joined:
    Oct 24, 2014
    Posts:
    6
    If you're not too concerned about performance in the short term, you can try a solution which corrects for incorrect height positioning at runtime:
    Code (CSharp):
    1. private void CorrectBaseHeight()
    2.     {
    3.         NavMeshHit navhit;
    4.         if (NavMesh.SamplePosition(GameObject.transform.position, out navhit, 10f, NavMesh.AllAreas))
    5.         {
    6.             Ray r = new Ray(navhit.position, Vector3.down);
    7.             RaycastHit hit;
    8.             if (Physics.Raycast(r, out hit, 10f, LayerMask.GetMask("Level")))
    9.             {
    10.                 _nav.baseOffset = -hit.distance;
    11.             }
    12.         }
    13.     }
     
  5. The-Wizzard-OZ

    The-Wizzard-OZ

    Joined:
    Apr 6, 2020
    Posts:
    1
    Hello, I am trying to do a voxel terrain with procedurally generated voxel blocks and NavMesh everything almost works perfectly other than my character can't go up the blocks, I tried to use NavMeshLink however that doesn't work well in my situation. Thankfully I found a way of fixing it on a not procedurally generated terrain made out of voxel blocks. If I decrease the voxelSize to 1 voxel per agent radius then everything works smoothly but I can only change it manually and not from a script. However, I know that it has something to do with
    Code (CSharp):
    1. NavmeshBuildSettings.voxelSize = 0.5f;
    but I really have no idea how to implement it. I would be really thankful if you could help me. Thank you!
     
  6. Bobster82

    Bobster82

    Joined:
    Jul 12, 2020
    Posts:
    1
    Ive also had problems with the height of the generated navmesh. I couldnt find any solution (so far)
    @rcabot wrote a function that looks too heavy for me.

    I used this for now:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         agent = GetComponent<NavMeshAgent>();
    4.         Invoke("changeHeight", 0.1f);
    5.     }
    6.  
    7.     void changeHeight() {
    8.         agent.baseOffset -= transform.position.y;
    9.     }
    Its nasty, but it works... after 0.1 sec, all units are on the original height again.
     
    Rootbeard likes this.