Commit 389843b4 authored by Sebastian Woelfel's avatar Sebastian Woelfel

box smooth movement

parent add6a02b
......@@ -150,8 +150,10 @@ public class PlayerTileMovement : MonoBehaviour
else
{
boxHit.transform.position += new Vector3(xDir, yDir, 0);
// boxHit.transform.position += new Vector3(xDir, yDir, 0);
//use Coroutine instead
Vector3 endPos = boxHit.transform.position + new Vector3(xDir, yDir, 0);
StartCoroutine(BoxSmoothMovement(boxHit.collider.gameObject, endPos));
}
}
}
......@@ -185,7 +187,9 @@ public class PlayerTileMovement : MonoBehaviour
}
else
{
boxLeftToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
// boxLeftToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
Vector3 endPos = boxLeftToPlayer.transform.position + new Vector3(xDir, yDir, 0);
StartCoroutine(BoxSmoothMovement(boxLeftToPlayer.collider.gameObject, endPos));
}
}
......@@ -203,7 +207,9 @@ public class PlayerTileMovement : MonoBehaviour
}
else
{
boxRightToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
// boxRightToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
Vector3 endPos = boxRightToPlayer.transform.position + new Vector3(xDir, yDir, 0);
StartCoroutine(BoxSmoothMovement(boxRightToPlayer.collider.gameObject, endPos));
}
}
......@@ -221,7 +227,9 @@ public class PlayerTileMovement : MonoBehaviour
}
else
{
boxUpToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
// boxUpToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
Vector3 endPos = boxUpToPlayer.transform.position + new Vector3(xDir, yDir, 0);
StartCoroutine(BoxSmoothMovement(boxUpToPlayer.collider.gameObject, endPos));
}
}
......@@ -239,7 +247,9 @@ public class PlayerTileMovement : MonoBehaviour
}
else
{
boxDownToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
// boxDownToPlayer.transform.position += new Vector3(moveDir.x, moveDir.y, 0);
Vector3 endPos = boxDownToPlayer.transform.position + new Vector3(xDir, yDir, 0);
StartCoroutine(BoxSmoothMovement(boxDownToPlayer.collider.gameObject, endPos));
}
}
}
......@@ -286,6 +296,19 @@ public class PlayerTileMovement : MonoBehaviour
turnAnimator.SetBool("isMoving", isMoving);
}
public IEnumerator BoxSmoothMovement(GameObject box, Vector3 end)
{
Vector3 startPos = box.transform.position;
for (float t = 0; t < moveTime; t += Time.deltaTime)
{
box.transform.position = Vector3.Lerp(startPos, end, t / moveTime);
yield return null;
}
box.transform.position = end;
}
private TileBase GetCell(Tilemap tilemap, Vector2 cellWorldPos)
{
return tilemap.GetTile(tilemap.WorldToCell(cellWorldPos));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment