- Home /
ai navigation help
i am making a ai that will go to a 10 different objects but it keeps stopping at the second one the script is not finished but i programmed it to go to the first second and third but it wont go to the third one this is what i wrote.Note: target1 and objecttarget1 is the same just in different form
#pragma strict
var target1 : Transform;
var target2 : Transform;
var target3 : Transform;
var target4 : Transform;
var target5 : Transform;
var target6 : Transform;
var target7 : Transform;
var target8 : Transform;
var target9 : Transform;
var target10 : Transform;
private var NavComponent : NavMeshAgent;
var monster : GameObject;
var objecttarget1 : GameObject;
var objecttarget2 : GameObject;
var objecttarget3 : GameObject;
var Target4 : GameObject;
var Target5 : GameObject;
var Target6 : GameObject;
var Target7 : GameObject;
var Target8 : GameObject;
var Target9 : GameObject;
var Target10 : GameObject;
function Start ()
{
NavComponent=this.transform.GetComponent(NavMeshAgent);
NavComponent.SetDestination(target1.position);
}
function Update ()
{
NavComponent.SetDestination(target2.position);
if(objecttarget2.active == false)
{
NavComponent.SetDestination(target3.position);
}
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == "myflag")
{
other.gameObject.SetActive(false);
}
}
I would make my own objects with an index and then either follow them numerically or have a publically accessible variable that states the next target
waypoint1.target = 2;
waypoint2.target = 3;
waypoint3.target = 1;
or something similar.
however im not familiar with navmeshes so I cannot specifically help with this problem
I'm not sure if I'm stating the same as bubzy, but wouldn't it make more sense to have a list/array with the target Transforms rather than 10 individual lines of code? You could easily iterate over the list/array.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
How to make it two seconds for Time.time? 2 Answers
How to make a selection system? 1 Answer