Search Unity

Odd Navmesh Pathfinding Behaviour

Discussion in 'Navigation' started by Murgilod, Feb 17, 2017.

  1. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,157
    I'm writing my own Navmesh Agent to get around some shortcomings of the default one and immediately I've run into a problem. It seems that corners aren't placed on slopes? Let me demonstrate with a few screenshots.



    In the first screenshot, you can see the path having no corners at all and just going in a straight line towards the player.



    In the second screenshot, you can see the corners of the path form perfectly.



    In this last screenshot, you can see a mix of the behaviours.

    If I had to guess, I'd say that the reason it's doing this is because the slopes fall well within the slope limit so it's possible to just path forward. However, this causes some problems for things like calculating path length and the like. Is something bugged here, or is it just something I'll have to deal with?

    Code (CSharp):
    1. void Start() {
    2.         controller = GetComponent<CharacterController> ();
    3.         path = new NavMeshPath();
    4.         elapsed = 0.0f;
    5.     }
    6.  
    7. void Update() {
    8.         if (!GameManager.gmInstance.isPaused) {
    9.             elapsed += Time.deltaTime;
    10.             if (elapsed > 1.0f) {
    11.                 elapsed -= 1.0f;
    12.                 NavMesh.CalculatePath(transform.position, target.position, NavMesh.AllAreas, path);
    13.             }
    14.  
    15.             Debug.Log (path.status);
    16.  
    17.             for (int i = 0; i < path.corners.Length - 1; i++) {
    18.                 Debug.DrawLine (path.corners [i], path.corners [i + 1], Color.red);
    19.             }
    20.         }
    21.     }