Unity NavMesh Obstacle

I am trying to create an RTS game in Unity and I have a problem finding a path. I use NavMesh to find paths, and it works well: blocks avoid static objects. But units do not avoid each other. There is a component called Obmacle NavMesh so that blocks can avoid non-static objects, but as I see it does not work with the NavMesh agent, because units try to avoid themselves. So how can units avoid each other?

+4
source share
2 answers

I know that some time has passed, but I have encountered the same problem in the last two hours. Finally, I managed to mix both components (NavMeshAgent and NavMeshObstacle). The only requirement is that they cannot be turned on at the same time. My strategy was to disable agents and obstacles (with the carve option turned on), and when I move the block, disconnect the obstacle and turn on the agent.

Just the last comment. I found that disabling the obstacle and including the agent in the same frame causes a slight problem of unit bias, so I had to use a coroutine to do this:

public IEnumerator EnableUnitMovementCoroutine()
{
    if (obstacle != null && obstacle.enabled)
    {
        obstacle.enabled = false;
    }

    yield return new WaitForEndOfFrame();

    if (agent != null && !agent.enabled)
    {
        agent.enabled = true;
        destinationSet = false;
    }

    yield return new WaitForEndOfFrame();

    unitMoving = true;
}

After that, simply use the agent methods to calculate the path. BTW, you can see navmesh in real time, including device obstacles, by selecting the “Navigation” tab in playback mode.

, !

PS. , :

_agent.pathStatus != NavMeshPathStatus.PathComplete

, , . . .

+3

NavMeshAgent , , . , .

, "avoidancePriority" , , . script, .

, , , , Unity , . , , NavMeshObstacle NavMesh... , , . (///...)

0

All Articles