- Home /
Question by
ZeroIQ_Scripter · Feb 04, 2020 at 04:45 PM ·
scripting problemtriggerscript.
Why doesn't my NavMeshAgent go to a position on trigger?
I wrote a script where a NavMeshAgent go to a given position on trigger it changes the position. But it only does the start function.
public Transform Position1;
public Transform Position2;
public Transform Position3;
public Transform Position4;
public NavMeshAgent agent;
void Start() {
agent = GetComponent<NavMeshAgent> ();
agent.SetDestination (Position1.transform.position);
}
void OnCollisionEnter(Collision col) {
if(col.gameObject.CompareTag("Position1")) {
agent.SetDestination(Position2.transform.position);
}
if (col.gameObject.CompareTag ("Position2")) {
agent.SetDestination (Position3.transform.position);
}
if (col.gameObject.CompareTag ("Position3")) {
agent.SetDestination (Position4.transform.position);
}
if (col.gameObject.CompareTag ("Position4")) {
agent.SetDestination (Position1.transform.position);
}
}
}
Comment
Answer by tormentoarmagedoom · Feb 05, 2020 at 02:56 PM
To use OnCollisionEnter some conditions must be met.
Read the documentation to be sure you are not forgeting something (rigidbody?, Not trigger? etc...)
And make some Debug.Log to be sure OnCollisionEnter ios beeing executed.
Bye!
Your answer
Follow this Question
Related Questions
How can i detect by script when a character enter a hole in object ? 1 Answer
How can I make two new methods one for the scaling one for the rotating to use from other scripts ? 2 Answers
How can i check and fire an event when the user look at specific object ? 0 Answers
Animator Trigger Not Working 1 Answer