diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /HardAnimations.cs |
+init
Diffstat (limited to 'HardAnimations.cs')
-rw-r--r-- | HardAnimations.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/HardAnimations.cs b/HardAnimations.cs new file mode 100644 index 0000000..b14ab1c --- /dev/null +++ b/HardAnimations.cs @@ -0,0 +1,64 @@ +using UnityEngine; + +public class HardAnimations : MonoBehaviour +{ + public bool isLeft; + + public HardPhysicsAnimation[] animations; + + private AnimationHandler animHandler; + + private Vector3 currentTarget; + + private Vector3 currentTargetGoal; + + private float counter; + + private Vector3 velocity; + + private StepHandler step; + + private ConfigurableJoint joint; + + private Quaternion startRot; + + private Quaternion startRotLocal; + + private CollisionChecker checker; + + private void Start() + { + animHandler = base.transform.root.GetComponent<AnimationHandler>(); + joint = GetComponent<ConfigurableJoint>(); + checker = GetComponent<CollisionChecker>(); + step = base.transform.root.GetComponent<StepHandler>(); + startRot = base.transform.rotation; + startRotLocal = base.transform.localRotation; + } + + private void Update() + { + Vector3 vector = ((step.isLeft != isLeft) ? animations[animHandler.animationState].targetRotationBack : animations[animHandler.animationState].targetRotationForward); + if (currentTargetGoal != vector) + { + if (counter >= animations[animHandler.animationState].delay) + { + counter = 0f; + currentTargetGoal = vector; + } + else + { + counter += Time.deltaTime; + } + } + checker.active = isLeft != step.isLeft; + velocity += (currentTargetGoal - currentTarget) * Time.deltaTime; + velocity *= animations[animHandler.animationState].friction; + currentTarget += velocity * animations[animHandler.animationState].movementAmount * Time.deltaTime; + joint.SetTargetRotationLocal(Quaternion.Euler(currentTarget), startRotLocal); + } + + private void FixedUpdate() + { + } +} |