Help plz

Hey all, i have been working on a new ai script for a semi intelligent bot, but i am stuck on one part. How would i remove a variable from a test, like if its an old waypoint and i want the bot to ignore it. here is the code, if anyone can help.

var nearestwaypoint : GameObject;
var lastwaypoint : GameObject;
var oldwaypoint : GameObject;
var waypointtag = "Waypoint";
var speed = 5;
private var loop : boolean = true;
var currentWaypoint = nearestwaypoint;

function Start (){
	BroadcastMessage("FindNearest");
}

function Update (){
	BroadcastMessage("FollowWaypoints");
}

function FollowWaypoints () {
	
}

function FindNearest () {
// Find all game objects with tag enemytag.
var gos : GameObject[];
gos = GameObject.FindGameObjectsWithTag(waypointtag);
GameObject in gos - lastwaypoint;
var closest : GameObject; 
var distance = Mathf.Infinity; 
var position = transform.position; 
// Iterate through them and find the closest one
for (var go : GameObject in gos) { 
var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude; 
if (curDistance < distance) { 
closest = go; 
distance = curDistance; 
} 

nearestwaypoint = closest;
}
Debug.Log("FindNearest");
return closest; 
}

Hi, its not really that clear from your question what you are trying to do exactly…

The code example you have included should return the closest enemy, what do you mean by “How would i remove a variable from a test”?

Taking a stab in the dark at what you are trying to do, you could tell your bot that the waypoint position it needs to go to is it’s own current position:-

currentWaypoint.position = transform.position;

Effectively saying that it has reached it’s target already?

Like I said, I’m just guessing here…

basically i want the last waypoint and the old waypoint out of the gos variable, so that its removed from the nearest gameobject test.

Add a check into your code, so when you Iterate through the gameobjects, you ignore if the game object your are currently testing == the last one or == the old one…?

Not tested, but something like this…

for (var go : GameObject in gos) {

if( (go != oldwaypoint) || (go != lastwaypoint) ) {

var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude;
if (curDistance < distance) {
closest = go;
distance = curDistance;

}

You could always set a flag of visited as a bool on each waypoint as theyre passed through and just add a check so that any flagged as visited are ignored

… or, if need it to be a more perminent act, just change the Tag on the visited ones when they are first chosen, so they are not 'enenmyTa’g, but ‘visitedTag’?

This way they will be automatically ignored from further searches, but you still have a way to reference them if you need them later…