I am trying to calculate difference in numbers between 2 Points, from a list of about 90 points. The code I have so far:
int positiveCounter = 0;
int positiveResetCounter = currentWayPointID;
int negativeCounter = 0;
int negativeResetCounter = currentWayPointID;
while ((currentWayPointID + positiveResetCounter) != pos)
{
positiveCounter++;
positiveResetCounter++;
if(positiveResetCounter > navigationTrack.AllWayPoints.Count)
{
positiveResetCounter = 0;
}
}
while((currentWayPointID+negativeResetCounter) != pos)
{
negativeCounter++;
negativeResetCounter--;
if(negativeResetCounter < 0)
{
negativeResetCounter = navigationTrack.AllWayPoints.Count;
}
}
if(positiveCounter <= negativeCounter)
{
MoveForward();
}
else if(negativeCounter < positiveCounter)
{
// MoveBack();
}
This works as intended but its too much for update to handle. How can I do this in less taxing way? To give bit more context I have list of waypoints and vehicle that moves on each the vehicle moves to the point that is closest to my mouses position. The path is circular so last waypoint connects first first(index 0). I am trying to determine shortest path to each waypoint in order to go forward or back and the code above is my attempt at calculating which way to go. I am not looking for a way to make it move as that already works.