Search Unity

Bizarre Navmesh issue

Discussion in '2D' started by BasharAlHotBod, Jun 24, 2021.

  1. BasharAlHotBod

    BasharAlHotBod

    Joined:
    Sep 30, 2020
    Posts:
    10
    I'm using NavMeshPlus for a grid based isometric game. I made the navmesh with no issues, and had a player character with an agent that would walk where the player clicked. Next I created an isometric grid object, used it to find the cell where the player clicks, and have the agent walk to that cell, rather than the exact location of the click. It worked fine until I realized the agent had serious issues if I tried moving it to a cell directly along its Y axis, in other words if the agent had to move in a straight line up or down. Moving within 3 cells directly up or down results in the agent not moving. Moving more than 3 cells directly up or down results in the agent stuttering slowly toward its destination, and getting stuck about half way.

    Initially thinking this was just a bug with my grid, I went back to my old non-grid movement, and realized this issue still exists. It was only more noticeable with the grid, because input clicks would automatically be translated to cell coordinates that would ensure the agent would move directly up or down. Even without the grid, the agent struggles to move directly up or directly down. The player doesn't have any weird components, in fact I turned off every component except the agent and the script below.

    If anyone has experienced this before issue before I'd appreciate some help. I wasn't able to find this issue discussed anywhere, and have no clue why it's happening.

    Code (CSharp):
    1. private NavMeshAgent navAgent;
    2.     private Vector2 navTarget;
    3.     private Vector3 gridTarget;
    4.  
    5.     private bool busy;
    6.     public float speed = 2;
    7.  
    8.     [SerializeField] Grid movementGrid;
    9.    
    10.     void Start()
    11.     {
    12.         navAgent = GetComponent<NavMeshAgent>();
    13.         navAgent.updateRotation = false;
    14.         navAgent.updateUpAxis = false;
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         if (conversationUI.activeSelf == true) busy = true;
    20.         else busy = false;
    21.  
    22.         if (!busy)
    23.         {
    24.             if(Input.GetMouseButtonDown(0))
    25.             {
    26.                 //non-grid movement
    27.                 //navTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    28.                 //navAgent.SetDestination(navTarget);
    29.                
    30.                 //grid movement
    31.                 navTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    32.                 gridTarget = movementGrid.GetCellCenterWorld(movementGrid.WorldToCell(navTarget));
    33.  
    34.                 navAgent.SetDestination(gridTarget);
    35.             }
    36.         }
    thanks
     
  2. BasharAlHotBod

    BasharAlHotBod

    Joined:
    Sep 30, 2020
    Posts:
    10
    For now I'm just using a duct tape fix of moving the player .001 units over on their x axis after they move, that way they'll never move directly up or down using the grid system. Stupid fix for a weird problem, but that's what I've got.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
  4. vhman

    vhman

    Joined:
    Aug 13, 2018
    Posts:
    360
    MelvMay likes this.