- Home /
The question is answered, right answer was accepted
Set navmesh destination if to object that is in range
Hello, I have am npc that follows the player. What I want to have happen is when an enemy enters the trigger (that is surrounding the npc) I want the npc to go after that specific enemy. I have many enemies in the scene. how would I do this? (A tutorial video would be helpful.
Answer by LoloBad · Feb 08, 2021 at 09:35 PM
If your fellow NPC has a Collider in trigger mode. You can use the method :
 void OnTriggerEnter(Collider other) { }
The code you're looking at may be something like :
 void OnTriggerEnter(Collider other)
 {
        if (other.CompareTag("Enemy"))
        {
               navAgent.SetDestination(other.transform.position);
        }
 }
Of course the enemies must be tagged "Enemy".
Follow this Question
Related Questions
i can't set destination, using AI Navmesh via raycast 1 Answer
NavMesh AI: follow only if seen 1 Answer
A lot of navmesh agents affects ai accuracy 0 Answers
NavMeshAgent resume original position and facing direction C# 0 Answers
My NavMeshAgent doesn't move at all!,Why my NavMeshAgent doesn't move at all? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                