Ok, so im following a tutorial on how to make a pathfinding strategy like game with turns (kinda like Civ). I got through the tutorial, and I was like, im going to make the piece lerp between squares instead of just jumping. Well, I managed to get it to work, but it jumps over tiles since there are two spaces it can move per turn. So, instead of the loop waiting for the lerps to finish, its just updating the final vector the object is supposed to be at, without waiting for the lerp to hit the first. With lerp in update, the lerp worked, but again it missed the first point and went directly to the second. So what I need it to do is wait before moving to the second point. Ive tried using a bool to hold the loop, but that didnt work as Update never got called as it was stuck on my loop (noob mistake I guess). So I decided to use a coroutine, but for some reason its not getting called at all. Heres the code
public void MoveNextTile()
{
float remainingMoves = moveSpeed;
while (remainingMoves > 0)
{
if (currentPath == null)
return;
//Get the cost from current tile to next tile
remainingMoves -= map.CostToEnterTile(currentPath[0].x, currentPath[0].y, currentPath[1].x, currentPath[1].y);
//Move us to the next tile in the sequence
toVector = map.TileCoordToWorldCoord(currentPath[1].x, currentPath[1].y);
Vector3 fromVec = map.TileCoordToWorldCoord(currentPath[0].x, currentPath[0].y);
MoveObject(fromVec, toVector, 1.0f);
//transform.position = map.TileCoordToWorldCoord(currentPath[1].x, currentPath[1].y);
//Remove the old current tile
currentPath.RemoveAt(0);
this.tileX = currentPath[0].x;
this.tileY = currentPath[0].y;
if (currentPath.Count == 1)
{
currentPath = null;
}
}
}
IEnumerator MoveObject(Vector3 source, Vector3 target, float overTime)
{
float startTime = Time.time;
while (Time.time < startTime + overTime)
{
transform.position = Vector3.Lerp(transform.position, target, (Time.time - startTime) / overTime);
transform.position = target;
yield return null;
}
transform.position = target;
}
Thank in advance for all the help.