Search Unity

Question NavMesh obstacle avoidance causing weird behaviour

Discussion in 'Navigation' started by Lekret, Jan 23, 2024.

  1. Lekret


    Sep 10, 2020
    Hi, I have simple formation system for ally characters in my game. There may be dozens of them hoarding around player.

    1. What I noticed is that when they run to player from long distance traversing around obstacles they can suddenly stop, i.e. they just run in a straight line with no other characters around, stop for a moment and continue moving.

    2. Second problem happens near very specific places, usually some walls when you approach them from specific side. Again, some units or even single unit don't stop entirely, but drop speed and approach final destination slowly. What I noticed is its NavMeshAgent velocity gizmo is "jumping" up and down 45 degrees offset instead of being a straight line, i.e it seems like NavMeshAgent can't decide where to go and constantly reevaluates velocity causing big speed drop.

    First problem happens when player is actually moving i.e. formation positions are being recalculated.
    And both problems happens only when ObstacleAvoidance is enabled on NavMeshAgents.
    Map is static and Player himself don't interact with NavMesh in any way (simple collider + rigidbody).
    Is there a way to fix it without disabling obstacle avoidance (I need characters to avoid each other)?

    UPD 1: Btw I just checked and enemies have the same problem, sometimes they stop when chasing player across obstacles.
    UPD 2: I checked and disabling obstacle avoidance don't solve first problem anymore. It's related to something else. Is it ok that NavMeshAgent stops when destination is being changed?
    UPD 3: Ok, I solved the first problem with stopping agents, it was caused by the fact that paths are calculated async and it seems that agents just stop after SetDestination if there are too many of them and/or paths are too long. NavMesh.pathfindingIterationsPerFrame = 10000 solves it (denies benefit of async, but whatever).
    Last edited: Jan 23, 2024
  2. Gabo_campitelli


    Oct 17, 2012
    Hi, i reply to your other post, this is caused by the issue i pointed in other post. You can't have a navmesh agent object be rigidbody enabled. have a navmesh agent separated and have the player/npc follow the agent.
    Lekret likes this.