- Home /
TILE MOVEMENT
Hi people, I am making a turn-based tile game, I made the system of path finding, it works well (heavy but well), anyway, the problem is with the movement of the unit.
I have the follow code to move:
if (canMove)
{
for (int i = 0; i < currentPath.Count; i++)
{
if (currentPath.Count > 0)
{
currentPath.RemoveAt(0);
Debug.Log("Removing " + i);
targetPosition = new Vector3(currentPath[i].x, 0.06f, currentPath[i].y);
lookAtTarget = new Vector3(targetPosition.x - transform.position.x, transform.position.y, targetPosition.z - transform.position.z);
playerRot = Quaternion.LookRotation(lookAtTarget);
transform.rotation = Quaternion.Slerp(transform.rotation, playerRot, rotateSpeed * Time.deltaTime);
transform.position = Vector3.MoveTowards(transform.position, targetPosition, forwardSpeed * Time.deltaTime);
currentState = CHAR_STATE.WALKING;
}
else
{
currentState = CHAR_STATE.IDLE;
moving = false;
canMove = false;
}
}
}
The logic is, the player must move tile by tile, to unit doesn't make him ignore the path and go through the tiles. So I made a looping to each tile in path, the problem is: I loop doesn't wait the unit movimentation, maybe I have to use StartCoroutine, but I don't know how to use it on it, could some one help me? (it's very important, if you cares xD) thank you.
Your answer
Follow this Question
Related Questions
Grid and or Tile System 0 Answers
How can I compare two tilemaps by color? 1 Answer
Get sprites from tile palate while using custom tile prefab brush 0 Answers
How to reach 2D Grid from script? How to reach every tilemap location and use them for pathfinding? 1 Answer
Making 2D Tilemap Areas Impassible During Runtime? 0 Answers