Search Unity

[NavMeshAgent][Basic] Multiple nav mesh agent slow down

Discussion in 'Navigation' started by YannDesigner, May 19, 2022.

  1. YannDesigner

    YannDesigner

    Joined:
    Jan 22, 2019
    Posts:
    1
    Hello,

    I'm starting unity and i want to play a bit with the NavMeshAgent to explore the possibilities.

    I succeeded to use it for the player's character link to a mouse right-clic and for an enemy that is targeting a gameobject in the scene, but as soon as my SpawnManager spawn a new enemy, my 2 enemies are drastically slowed down and i don't realy understand why.

    Here is my enemy's code :
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.AI;
    4.  
    5. public class EnemyBehavior : MonoBehaviour
    6. {
    7.     //my NavMeshAgent
    8.     public NavMeshAgent navMeshAgent;
    9.     //the target's variables
    10.     private GameObject TargetBase;
    11.     Vector3 pos;
    12.    
    13.     void Start()
    14.     {
    15.         //set the target
    16.         TargetBase = GameObject.Find("Base");
    17.         pos = TargetBase.transform.position;
    18.        
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.         //move to the target using NavMeshAgent
    25.         navMeshAgent.destination = pos;
    26.        
    27.     }
    28. }
    29.  
    I have set the NavMeshAgent in the script, into the Inspector :
    upload_2022-5-19_14-24-48.png

    If I spawn only one enemy, everythings is working correclty, but as soon the seconde enemy spawn, both are slowed. Other information my player character, which is also using the NavMeshAgent, is not impacted.

    Any of you have an idea about my mistake?

    Thanks ;)
     

    Attached Files: