[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

@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 2121127948713986199} - component: {fileID: 2121127948713986199}
m_Layer: 0 m_Layer: 0
m_Name: Pulver m_Name: Pulver
m_TagString: Untagged m_TagString: CharacterArt
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0

View File

@@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 3714001194702331617} - component: {fileID: 3714001194702331617}
m_Layer: 0 m_Layer: 0
m_Name: Trafalgar m_Name: Trafalgar
m_TagString: Untagged m_TagString: CharacterArt
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0

View File

@@ -34,7 +34,7 @@ namespace Pathfinding {
const double updateCheckRate = 1F; const double updateCheckRate = 1F;
/// <summary>URL to the version file containing the latest version number.</summary> /// <summary>URL to the version file containing the latest version number.</summary>
const string updateURL = "http://www.arongranberg.com/astar/version.php"; const string updateURL = "https://www.arongranberg.com/astar/version.php";
/// <summary>Last time an update check was made</summary> /// <summary>Last time an update check was made</summary>
public static System.DateTime lastUpdateCheck { public static System.DateTime lastUpdateCheck {

View File

@@ -28,9 +28,22 @@ public class FollowerController : MonoBehaviour
public float stopThreshold = 0.1f; // Stop moving when within this distance public float stopThreshold = 0.1f; // Stop moving when within this distance
private float playerMaxSpeed = 5f; private float playerMaxSpeed = 5f;
private Animator animator;
private Transform artTransform;
void Awake() void Awake()
{ {
aiPath = GetComponent<AIPath>(); 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() void OnEnable()
@@ -155,6 +168,23 @@ public class FollowerController : MonoBehaviour
currentSpeed = 0f; 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) // Command follower to go to a specific point (pathfinding mode)

View File

@@ -18,12 +18,24 @@ public class PlayerTouchController : MonoBehaviour, ITouchInputConsumer
Rigidbody rb3d; Rigidbody rb3d;
Rigidbody2D rb2d; Rigidbody2D rb2d;
AIPath aiPath; // Reference to AIPath AIPath aiPath; // Reference to AIPath
private Animator animator;
private Transform artTransform;
void Awake() void Awake()
{ {
rb3d = GetComponent<Rigidbody>(); rb3d = GetComponent<Rigidbody>();
rb2d = GetComponent<Rigidbody2D>(); rb2d = GetComponent<Rigidbody2D>();
aiPath = GetComponent<AIPath>(); // Get AIPath component 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() 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 // Remove FixedUpdate and MoveTowardsTarget, as AIPath handles movement
} }

View File

@@ -3,7 +3,8 @@
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 3 serializedVersion: 3
tags: [] tags:
- CharacterArt
layers: layers:
- Default - Default
- TransparentFX - TransparentFX