- Home /
navmesh multiple targets
Lads,
I'm using NavMeshAgent for a little zombie hunting, however I'm having a problem setting multiple target destinations. Currently I've just edited the SampleAgentScript by adding extra targets like so:
public class SampleAgentScript : MonoBehaviour
{
public Transform target1;
public Transform target2;
public Transform target3;
public Transform target4;
NavMeshAgent agent;
void Start ()
{
agent = GetComponent<NavMeshAgent> ();
}
void Update ()
{
agent.SetDestination(target1.position);
agent.SetDestination(target2.position);
agent.SetDestination(target3.position);
agent.SetDestination(target4.position);
}
}
The result however are not predictable particularly when I add another agent... I'd assume that the navmeshagent would go to the first target, then the second, etc... but no such luck. The navmeshgagent doesn't seem to move in a predictable fashion. Any thoughts?...
Thanks,
Stef
What you've written will, in every single frame that the game runs, set the destination to target1, then target2, 3, then 4. And, on the next frame, it will do the same again.
I suspect what you meant to do was to wait until the agent reached target1 before setting target2 as the next destination...
Your answer
Follow this Question
Related Questions
Use multiple NavMesh ? -1 Answers
Tell if navmeshagent has reached target? 0 Answers
Can I have 2 navmeshes but only have 1 effected by a nav mesh obstacle? 0 Answers
Multiple Targets 1 Answer
How do I display two scenes at once 1 Answer