Search Unity

Agent ignores target destination if target/player is close to wall and then starts running randomly

Discussion in 'Navigation' started by scrollingsquirrel, Oct 7, 2019.

  1. scrollingsquirrel

    scrollingsquirrel

    Joined:
    Oct 7, 2019
    Posts:
    1
    • The pathing code is as follows:
      navMeshAgent.destination = player.position;
    • The destination is always slightly offset if the player is out of the navmesh (near a wall) to the closest point on the navmesh as you would expect.

    • For debug purposes I have done a NavMesh.CalculatePath twice. One to check the path to the player's position and another for the target position which is offset as mentioned before. Here's the kicker. The player is unreachable, that's normal, but the destination is reachable despite the fact that the agent decides to do laps around the NavMesh. (sometimes it hits a corner/edge of the navmesh and then goes back to it's target)

    • Even if I move the player out of the wall and into completely open space nothing changes. I just have to wait until it's finished it's marathon.
    This makes no sense to me. How can an agent have an active path that is valid and still decide to go crazy doing laps? And how would one stop the laps from happening if there was a total blockage in the first place?

    There's at least some logic in it running around not knowing what to do if things are blocked, but there is no block for it's destination especially if I double check by moving the player into open space.

    I know agent radius is important, but a few days ago, this has worked completely fine in the same in-game location with the same navmesh with the same radius, so something else seems to be the issue.

    What sort of things should I be looking out for here?
     
    Last edited: Oct 8, 2019