[Player][Animation] Setup speed variables to play animations on Trafalgar and Pulver

This commit is contained in:
Michal Pikulski
2025-09-02 15:49:21 +02:00
parent 721aac3904
commit fdf871aac0
6 changed files with 57 additions and 4 deletions

View File

@@ -18,12 +18,24 @@ public class PlayerTouchController : MonoBehaviour, ITouchInputConsumer
Rigidbody rb3d;
Rigidbody2D rb2d;
AIPath aiPath; // Reference to AIPath
private Animator animator;
private Transform artTransform;
void Awake()
{
rb3d = GetComponent<Rigidbody>();
rb2d = GetComponent<Rigidbody2D>();
aiPath = GetComponent<AIPath>(); // Get AIPath component
// Find art prefab and animator
artTransform = transform.Find("CharacterArt");
if (artTransform != null)
{
animator = artTransform.GetComponent<Animator>();
}
else
{
animator = GetComponentInChildren<Animator>(); // fallback
}
}
void Start()
@@ -70,5 +82,15 @@ public class PlayerTouchController : MonoBehaviour, ITouchInputConsumer
}
}
void Update()
{
// Update animator speed parameter
if (animator != null && aiPath != null)
{
float normalizedSpeed = aiPath.velocity.magnitude / aiPath.maxSpeed;
animator.SetFloat("Speed", Mathf.Clamp01(normalizedSpeed));
}
}
// Remove FixedUpdate and MoveTowardsTarget, as AIPath handles movement
}