Search Unity

Detecting changes in path due to Navmesh Obstacles

Discussion in 'Navigation' started by Yandalf, Sep 18, 2018.

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I'm currently prototyping a crowd simulation where groups of people try to cross an intersection with alternating traffic.
    Right now I simulated the traffic by toggling empty gameObjects that have a carving NavMeshObstacle and spawn cars on and off in either direction. This causes the people to stop right in front of where the traffic drives past until it stops, then they can continue on their path.
    Gif of the current state: https://imgur.com/kX7DLtl

    However, I notice some of my characters getting stuck in corners as they try to move to their destination but get cut off by the obstacles, and even another change in the obstacles doesn't make them change their pathing.
    It seems that there is no way to check when the navmesh gets changed by obstacles at this point, and obstacles also are apparently not considered when checking if a path is reachable. This is causing quite some problems right now as my agents try to push each other further and further to reach their intermediate target.

    My current idea is to write a separate script that basically checks for more intermediate destinations and just lets the agents rest there until the next section in the path becomes unblocked again. This could technically be done by changing the NavMesh Areas since those do trigger a recalculation, but since that's an expensive operation I'd rather avoid that. Anyone know of a way to perhaps get more direct access to the Navmesh segments your agent is trying to use and to somehow check these against the obstacles?