Search Unity

Moving agent avoid other moving agent

Discussion in 'Navigation' started by Pytchoun, Dec 7, 2021.

  1. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    I use nav mesh agent and my zombie try to reach the player position but instead of try to get around they gang bang with other zombie in front of them, how to improve that ? Like get around for take the other side or just don't move if they cant reach the player position because other zombie are in circle around the player.
    Also my zombie moving my Player, do you know how i can fixe that ?
    My Player use CharacterController.
    My Zombie use Nav Mesh Agent, Rigidbody and Capsule Collider.

    ```cs
    private void Chase()
    {
    if (!_navMeshAgent.pathPending)
    {
    if (NavMesh.SamplePosition(_targetDetection.Target.transform.position, out NavMeshHit hit, 20f, _navMeshAgent.areaMask))
    {
    _navMeshAgent.SetDestination(hit.position);
    }
    }
    }
    ```
     
    Last edited: Dec 8, 2021
  2. emirkivrak-dev

    emirkivrak-dev

    Joined:
    Jan 14, 2020
    Posts:
    10
    You have to mark agents as a obstacle, and make a runtime bake, but its hard to do. If you are going to try u can use https://github.com/Unity-Technologies/NavMeshComponents.

    But before that in my opinion;
    Try to decrease diameter of agents and their capsule colliders, maybe you get better results without it.
     
  3. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    268
    Might I recommend using a surround algorithm such as this:
     
    jhocking likes this.