diff options
Diffstat (limited to '_ActiveRagdoll/Actions/Gravity.cs')
-rw-r--r-- | _ActiveRagdoll/Actions/Gravity.cs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/_ActiveRagdoll/Actions/Gravity.cs b/_ActiveRagdoll/Actions/Gravity.cs new file mode 100644 index 0000000..42f3125 --- /dev/null +++ b/_ActiveRagdoll/Actions/Gravity.cs @@ -0,0 +1,52 @@ +using UnityEngine; + +public class Gravity : MonoBehaviour +{ + public float baseGravity;//5 + + public float scalingGravity;//70 + + private RigidbodyHolder allRigs;//14个全部 + + private StandingDataHandler standingData; + + private Holding holding; + + private PlayerDeath death; + + private void Start() + { + death = GetComponent<PlayerDeath>(); + allRigs = GetComponent<RigidbodyHolder>(); + standingData = GetComponent<StandingDataHandler>(); + holding = GetComponent<Holding>(); + } + + private void FixedUpdate() + { + if (death.dead) + { + return; + } + for (int i = 0; i < allRigs.GetAllRigs().Length; i++) + { + // standingData.sinceGrounded是离地时间 + Vector3 g = Vector3.down * baseGravity + Vector3.down * scalingGravity * standingData.sinceGrounded; + // 重力=持久的基础重力+随着离地状态变化的重力,离地时增加额外重力 + allRigs.GetAllRigs()[i].AddForce(g, ForceMode.Acceleration); + //Debug.Log(g); + //Debug.Log(standingData.sinceGrounded); + } + 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); + } + } + } +} |