movement anim

This commit is contained in:
reisenlol 2026-01-06 23:58:46 -08:00
parent b7562d53ae
commit 5776d5e889
No known key found for this signature in database
4 changed files with 114 additions and 54 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Collections;
using UnityEngine;
public class Entity : MonoBehaviour
@ -10,6 +11,7 @@ public class Entity : MonoBehaviour
[Header("Movement")]
public int maxMovement;
public TileObject currentTile;
public float moveAnimSpeed;
[Header("Flags")]
public bool canMove = true;
@ -34,4 +36,22 @@ public class Entity : MonoBehaviour
{
}
public virtual IEnumerator MoveToLocation(TileObject[] pathToMove)
{
float currentState = 0;
int currentTileList = 0;
while (currentTileList < pathToMove.Length)
{
currentState += Time.deltaTime * moveAnimSpeed;
transform.position = Vector2.Lerp(currentTile.transform.position, pathToMove[currentTileList].transform.position, currentState);
if (currentState > 1)
{
currentTile = pathToMove[currentTileList];
currentState = 0;
currentTileList++;
}
yield return null;
}
}
}