Hey guys I have made a simple waypoint function but I am having a bit of trouble. What I want it to do is this:
locate closest waypoint, go to it, if it reaches it, search again without including the one its currently on.
As you can see in the code below: (distanceToWayPoints[closest] < totalDistance) that block of code has to be changed
void WayPoint()
{
// total distance
int totalDistance = 10;
// goes through all the waypoints
for (int nStart = 0; nStart < MaxNoOfWPs; nStart++)
{
// calculates all the distances from the monster to each waypoint
distanceToWayPoints[nStart] = Vector3.Distance(everyWayPointInLevel[nStart].transform.position, transform.position);
// if its the closest waypoint than have it be the target
if (distanceToWayPoints[nStart] < distanceToWayPoints[closest])
{
closest = nStart;
target = everyWayPointInLevel[closest].transform.position;
//used as temp to know which one was the last wp
lastWayPoint = everyWayPointInLevel[closest].transform.position;
}
// if the enemy gets close enough to the waypoint, trigger this =
if (distanceToWayPoints[closest] < totalDistance)
{
// THIS HAS TO BE CHANGED
// so that instead of placing the wp at 0,0,0
// it makes it not calculate the wp in the search
everyWayPointInLevel[closest].transform.position = new Vector3(0,0,0);
}
}
// animation
animation.CrossFade("walk");
// speed
speed = walkingSpeed;
}