summaryrefslogtreecommitdiff
path: root/HardAnimation.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /HardAnimation.cs
+init
Diffstat (limited to 'HardAnimation.cs')
-rw-r--r--HardAnimation.cs61
1 files changed, 61 insertions, 0 deletions
diff --git a/HardAnimation.cs b/HardAnimation.cs
new file mode 100644
index 0000000..3821be6
--- /dev/null
+++ b/HardAnimation.cs
@@ -0,0 +1,61 @@
+using UnityEngine;
+
+public class HardAnimation : MonoBehaviour
+{
+ public bool isLeft;
+
+ public Vector3 targetRotationForward;
+
+ public Vector3 targetRotationBack;
+
+ private Vector3 currentTarget;
+
+ private Vector3 currentTargetGoal;
+
+ public float friction;
+
+ public float movementAmount;
+
+ public float delay;
+
+ private float counter;
+
+ private Vector3 velocity;
+
+ private StepHandler step;
+
+ private ConfigurableJoint joint;
+
+ private Quaternion startRot;
+
+ private Quaternion startRotLocal;
+
+ private void Start()
+ {
+ joint = GetComponent<ConfigurableJoint>();
+ step = base.transform.root.GetComponent<StepHandler>();
+ startRot = base.transform.rotation;
+ startRotLocal = base.transform.localRotation;
+ }
+
+ private void Update()
+ {
+ Vector3 vector = ((step.isLeft != isLeft) ? targetRotationBack : targetRotationForward);
+ if (currentTargetGoal != vector)
+ {
+ if (counter >= delay)
+ {
+ counter = 0f;
+ currentTargetGoal = vector;
+ }
+ else
+ {
+ counter += Time.deltaTime;
+ }
+ }
+ velocity += (currentTargetGoal - currentTarget) * Time.deltaTime;
+ velocity -= velocity * friction * Time.deltaTime;
+ currentTarget += velocity * movementAmount * Time.deltaTime;
+ joint.SetTargetRotationLocal(Quaternion.Euler(currentTarget), startRotLocal);
+ }
+}