I am moving an object around from one node to another. I need to tell the object to stop moving when it has reached its destination node.
I am currently using this algorithm for movement and node checking
if (!isFinished)
{
// If the level has arrived at the current destination node and not at the final node
// Destination node is based on the interpolated points on the spline
if (AtNode(catmullRomSpline.InterpolatedPoints[nodeIndex], node))
{
// If we have not reached the final node/interpolated point on spline
if (nodeIndex + 1 < catmullRomSpline.InterpolatedPoints.Count)
{
// Increase the node index
nodeIndex++;
}
else
{
isFinished = true;
}
}
// Now move object unless finished is true
The problem I have is that I don't want to do any of the above if the isFinished boolean is true but if it is flagged as true in the method then the object will still be moved for that frame. This is because the isFinished is only checked at the start of the method.
How can I change the method to avoid this or exit correctly once isFinished is flagged as true?