[Player][Animation] Setup speed variables to play animations on Trafalgar and Pulver
This commit is contained in:
@@ -28,9 +28,22 @@ public class FollowerController : MonoBehaviour
|
||||
public float stopThreshold = 0.1f; // Stop moving when within this distance
|
||||
private float playerMaxSpeed = 5f;
|
||||
|
||||
private Animator animator;
|
||||
private Transform artTransform;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
aiPath = GetComponent<AIPath>();
|
||||
// Find art prefab and animator
|
||||
artTransform = transform.Find("CharacterArt");
|
||||
if (artTransform != null)
|
||||
{
|
||||
animator = artTransform.GetComponent<Animator>();
|
||||
}
|
||||
else
|
||||
{
|
||||
animator = GetComponentInChildren<Animator>(); // fallback
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
@@ -155,6 +168,23 @@ public class FollowerController : MonoBehaviour
|
||||
currentSpeed = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
// Update animator speed parameter
|
||||
if (animator != null)
|
||||
{
|
||||
float normalizedSpeed = 0f;
|
||||
if (isManualFollowing)
|
||||
{
|
||||
// Use currentSpeed for manual following
|
||||
normalizedSpeed = currentSpeed / playerMaxSpeed;
|
||||
}
|
||||
else if (aiPath != null)
|
||||
{
|
||||
// Use aiPath velocity for pathfinding mode
|
||||
normalizedSpeed = aiPath.velocity.magnitude / playerMaxSpeed;
|
||||
}
|
||||
animator.SetFloat("Speed", Mathf.Clamp01(normalizedSpeed));
|
||||
}
|
||||
}
|
||||
|
||||
// Command follower to go to a specific point (pathfinding mode)
|
||||
|
||||
@@ -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