summaryrefslogtreecommitdiff
path: root/Assembly_CSharp/GamePlay/WalkAnimator.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-11-26 23:52:30 +0800
committerchai <215380520@qq.com>2023-11-26 23:52:30 +0800
commit626381f061cde0c78564f6336e3131835cf20a5b (patch)
treed9991d6eda6ae5d7649ac91ecaa3b4dc833cd4c3 /Assembly_CSharp/GamePlay/WalkAnimator.cs
parent0e63c4a2c6dec8dfa260501fb7d73750261ea7b7 (diff)
* move
Diffstat (limited to 'Assembly_CSharp/GamePlay/WalkAnimator.cs')
-rw-r--r--Assembly_CSharp/GamePlay/WalkAnimator.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/Assembly_CSharp/GamePlay/WalkAnimator.cs b/Assembly_CSharp/GamePlay/WalkAnimator.cs
new file mode 100644
index 0000000..4f2b997
--- /dev/null
+++ b/Assembly_CSharp/GamePlay/WalkAnimator.cs
@@ -0,0 +1,55 @@
+using System;
+using UnityEngine;
+
+public class WalkAnimator : MonoBehaviour
+{
+ private Pathfinder p;
+
+ [SerializeField]
+ private Transform directionalTransform;
+
+ [SerializeField]
+ private Transform rotationalOffsetTransform;
+
+ [SerializeField]
+ private Transform artTransform;
+
+ [SerializeField]
+ private float strideLength = 1f;
+
+ [SerializeField]
+ private float strideHeight = 1f;
+
+ [SerializeField]
+ private float sideAngles = 20f;
+
+ [SerializeField]
+ private float strideVariationPercentage = 0.1f;
+
+ private float step;
+
+ private Vector3 preiviousPosition;
+
+ private Vector3 direction;
+
+ private void Start()
+ {
+ strideLength = UnityEngine.Random.Range(strideLength * (1f - strideVariationPercentage), strideLength * (1f + strideVariationPercentage));
+ strideHeight = UnityEngine.Random.Range(strideHeight * (1f - strideVariationPercentage), strideHeight * (1f + strideVariationPercentage));
+ p = GetComponent<Pathfinder>();
+ preiviousPosition = base.transform.position;
+ }
+
+ private void FixedUpdate()
+ {
+ direction = base.transform.position - preiviousPosition;
+ preiviousPosition = base.transform.position;
+ if (direction.sqrMagnitude != 0f)
+ {
+ directionalTransform.rotation = Quaternion.LookRotation(direction, Vector3.up);
+ }
+ step = (step + p.speed * Time.fixedDeltaTime / strideLength) % 2f;
+ artTransform.localPosition = strideHeight * Vector3.up * Mathf.Abs(Mathf.Cos(step * (float)Math.PI));
+ artTransform.localEulerAngles = new Vector3(sideAngles * Mathf.Sin(step * (float)Math.PI), 0f, 0f);
+ }
+}