Why after recalculating path our Enemy doesn’t start from the beginning of the path, but contonues to move from current position. If I understand it correct, for(int… ) loop counts i (for example it start to recalculate path when Enemy moves to Tile i =11) so after RecalculatingPath() Enemy continues moving to the Tile i = 11 where ever it is now, but not starts again from i = 0?
IEnumerator FollowPath(){
for(int i = 0; i < path.Count; i++)
{
Vector3 startPosition = transform.position;
Vector3 endPosition = gridManager.GetPositionFromCoordinates(path[i].coordinates);
float travelPercent = 0f;
transform.LookAt(endPosition);
while(travelPercent < 1f) {
travelPercent +=Time.deltaTime * moveSpeed;
transform.position = Vector3.Lerp(startPosition, endPosition, travelPercent);
yield return new WaitForEndOfFrame();
}
}
FinishPath();
}