Search Unity

[Live-Baking | Unity 2018.2.6f1] Agent's Nav-Mesh is floating because of radius [SOLVED]

Discussion in 'Navigation' started by Benjaminupjers, Sep 21, 2018.

  1. Benjaminupjers

    Benjaminupjers

    Joined:
    Jul 13, 2018
    Posts:
    2
    Hey Guys,

    I'm currently running into a Problem with live baking of different Nav-Meshes.
    My scene consists of a box-collider, which is basically a ground layer.

    collider.PNG


    Now I'm trying to bake some Nav-Meshes (at runtime because Scene changes) with the following Agents.


    upload_2018-9-21_10-45-49.png upload_2018-9-21_10-46-7.png

    The result I'm getting are really strange. The navmesh for the first agent is okay but the second ( Big-Excavator-Agent) is floating in the air. I honestly have no clue why this behaviour occurs. Seems to be some kind of big with the radius?

    upload_2018-9-21_10-48-16.png

    Somebody knows anything about this problem and how to solve this? Or is this just me being stupid?
     
  2. Benjaminupjers

    Benjaminupjers

    Joined:
    Jul 13, 2018
    Posts:
    2
    [Solution]
    Hi again,

    I tested a lot and found out, that overriding the "Default Voxel Size" of the NavMeshSurface-Component is going to fix this issue. It's important to note, that an increase of voxel is going to result in longer bake times!

    solution.PNG

    [Alternative Solution]
    Since longer bake times are somewhat annoying and can brake your neck on old platforms you might want to consider the alternative solution I found. Once you setup your agent and placed it on the navmesh, wait for the next frame and set the NavMeshAgent.baseOffset to the negative current transform height of your gameobject.
    Something like this:

    Code (CSharp):
    1.  
    2. public void InitiateNavMeshAgent()
    3. {
    4.       Agent.enabled = true;
    5.       Agent.Warp(transform.position);
    6.       StartCoroutine(ApplyOffsetAtNextFrame());
    7. }
    8.  
    9. private IEnumerator ApplyOffsetAtNextFrame()
    10. {
    11.       yield return null;
    12.       Agent.baseOffset = -transform.position.y;
    13. }
    14.  
    This will result in an agent which is placed on the "floating" navmesh but the object itself is shown at the right position.

    Important Note!
    If you want to use this alternative approach, make sure to factor in the offset while calculating a target/path. Otherwise your agent may not find a path to the target. Code would look something like that:

    Code (CSharp):
    1.  
    2. private IEnumerator CMoveToTarget(Vector3 pTarget)
    3. {
    4.    Vector3 offsetTarget = new Vector3(pTarget.x, -Agent.baseOffset ,pTarget.z);
    5.    NavMeshPath path = new NavMeshPath();
    6.    yield return Agent.CalculatePath(offsetTarget,path);
    7. }
    8.  
     
    Zante likes this.