From c9fc4fbbe205ff69fa20ded822b2214847b59726 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Mon, 18 Mar 2024 10:03:48 +0800 Subject: *misc --- _ActiveRagdoll/Actions/Gravity.cs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 _ActiveRagdoll/Actions/Gravity.cs (limited to '_ActiveRagdoll/Actions/Gravity.cs') 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(); + allRigs = GetComponent(); + standingData = GetComponent(); + holding = GetComponent(); + } + + 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); + } + } + } +} -- cgit v1.1-26-g67d0