using UnityEngine; public class PlayerAnimationManager : MonoBehaviour { [SerializeField] private Animator animator; [SerializeField] private float playerMoveSpeed = 5; private float sprintThreshold; private Vector3 lastPosition; private void OnValidate() { if (animator == null) animator = GetComponentInChildren(); } private void Start() { sprintThreshold = playerMoveSpeed * 1.5f * Time.fixedDeltaTime; } public void AnimateBasedOnSpeed() { lastPosition.y = transform.position.y; float distanceMoved = Vector3.Distance(transform.position, lastPosition); animator.SetBool("IsMoving", distanceMoved > 0.01f); animator.SetBool("IsSprinting", distanceMoved > sprintThreshold); lastPosition = transform.position; } }