From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- Gravity.cs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Gravity.cs (limited to 'Gravity.cs') diff --git a/Gravity.cs b/Gravity.cs new file mode 100644 index 0000000..f646f0c --- /dev/null +++ b/Gravity.cs @@ -0,0 +1,47 @@ +using UnityEngine; + +public class Gravity : MonoBehaviour +{ + public float baseGravity; + + public float scalingGravity; + + private RigidbodyHolder allRigs; + + private StandingDataHandler standingData; + + private Holding holding; + + private PlayerDeath death; + + private void Start() + { + death = GetComponent(); + allRigs = GetComponent(); + standingData = GetComponent(); + holding = GetComponent(); + } + + private void FixedUpdate() + { + if (death.dead) + { + return; + } + for (int i = 0; i < allRigs.GetAllRigs().Length; i++) + { + allRigs.GetAllRigs()[i].AddForce(Vector3.down * baseGravity + Vector3.down * scalingGravity * standingData.sinceGrounded, ForceMode.Acceleration); + } + if ((bool)holding) + { + if ((bool)holding.heldObject) + { + holding.heldObject.rig.AddForce(Vector3.down * baseGravity + Vector3.down * scalingGravity * standingData.sinceGrounded, ForceMode.Acceleration); + } + if ((bool)holding.heldObjectOffHand) + { + holding.heldObjectOffHand.rig.AddForce(Vector3.down * baseGravity + Vector3.down * scalingGravity * standingData.sinceGrounded, ForceMode.Acceleration); + } + } + } +} -- cgit v1.1-26-g67d0