that is a screen shot of my simple code , i am only try to make my gameobject go to point index of 0
then go to point index of 1 /2/3 etc …
but it is give me awful result
that is wrong here !
You are iterating the whole collection at once in the for loop. You’d have to review the process a bit:
Transform [] points;
int index = 0;
void Update(){
Move();
}
void Move(){
Tank.position = Vector3.MoveTowards(Tank.position, points[index].position, 2f);
float magnitude = Vector3.Distance(Tank.position, points[index].position);
if(magnitude < 0.1f){ // You can set the value smaller or bigger
if(++index == points.Length){
index = 0; // Code here
}
}
}
So in this setup, your guy will move from 0 to 1 then 2 and back to 0.
If you want to stop at 2 then change the section at Code here.