summaryrefslogtreecommitdiff
path: root/StandingDataHandler.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 /StandingDataHandler.cs
+init
Diffstat (limited to 'StandingDataHandler.cs')
-rw-r--r--StandingDataHandler.cs69
1 files changed, 69 insertions, 0 deletions
diff --git a/StandingDataHandler.cs b/StandingDataHandler.cs
new file mode 100644
index 0000000..10a1473
--- /dev/null
+++ b/StandingDataHandler.cs
@@ -0,0 +1,69 @@
+using UnityEngine;
+
+public class StandingDataHandler : MonoBehaviour
+{
+ public Rigidbody mainRig;
+
+ public float sinceGrounded;
+
+ public float sinceLanded;
+
+ public bool isGrounded;
+
+ public float distanceToGround = 1f;
+
+ private bool hasRecievedTouchedGround;
+
+ private MovementDataHandler moveMentData;
+
+ private PlayerKnockback knockback;
+
+ private WobbleShake wobbleShake;
+
+ private void Start()
+ {
+ wobbleShake = GetComponentInChildren<WobbleShake>();
+ knockback = GetComponent<PlayerKnockback>();
+ }
+
+ private void FixedUpdate()
+ {
+ sinceGrounded += Time.fixedDeltaTime;
+ sinceLanded += Time.fixedDeltaTime;
+ moveMentData = GetComponent<MovementDataHandler>();
+ if ((double)sinceGrounded > 0.1)
+ {
+ isGrounded = false;
+ }
+ }
+
+ private void LateUpdate()
+ {
+ hasRecievedTouchedGround = false;
+ }
+
+ public void TouchGround(float distance, Vector3 normal)
+ {
+ if (sinceGrounded > 0.5f && (bool)wobbleShake)
+ {
+ wobbleShake.AddShake(-Vector3.up * 5f * Mathf.Pow(sinceGrounded, 1.5f), 0.8f);
+ }
+ if (sinceGrounded > 0.5f)
+ {
+ Land(sinceGrounded);
+ }
+ sinceGrounded = 0f;
+ isGrounded = true;
+ if (distance > distanceToGround || !hasRecievedTouchedGround)
+ {
+ distanceToGround = distance;
+ }
+ hasRecievedTouchedGround = true;
+ moveMentData.SetSlope(normal);
+ }
+
+ private void Land(float landForce)
+ {
+ sinceLanded = 0f;
+ }
+}