[Player][Animation] Setup speed variables to play animations on Trafalgar and Pulver
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user