Waypoint AI not reacting as expected.

I have a large ship, with this code attached →

var Waypoints : Transform[];
var currentWaypoint : int;

function Update () {
	transform.parent.GetComponent("SmoothLookAt").target = Waypoints[currentWaypoint];
}

function OnTriggerEnter (collisionInfo : Collider) {
	if(collisionInfo.gameObject.tag == "BomberWaypoint"){
			currentWaypoint += 1;
	}
	
	if(currentWaypoint > Waypoints.length - 1){
		currentWaypoint = 0;
	}
}	


@script AddComponentMenu("AI Scripts/Bomber AI");

This code works just fine, until it gets hit with a laser or missile. The colliders of both the waypoints and the ship are overlapping, that is very apparent. Once it is hit, it starts circling around currentWaypoint even after they’ve touched.

So what am I doing wrong here? I can’t have it start circling waypoints just because it got hit by a laser…

Well, there are a few things i noticed, #1 why are you using “[ ]” those brackets? but secondly, i tried this AI style once and i got it to work. But for me, instead of detecting a collision between the waypoint and the AI, try measuring the distance between the two and when it gets to a certain distance away from the waypoint, it switches to the other waypoint.

Also i think the problem is your “(collisionInfo : Collider)” needs to be “(collisionInfo : Collision)”

when you use triggers, it has to be (collisionInfo : Collider), it wont take (collisionInfo : Collision).

I will try the distance method. I like the idea.

I used brackets because it is an array of waypoints, and it is easier to refer to each one with algorithms instead of conditions.

[SOLVED]

Use

if(distance < threshold){
               currentWaypoint += 1;
       }