From 134f1deb971b0514a26e04e23926f91983a5497f Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:38:18 +0800 Subject: * move --- _ActiveRagdoll/RotationHandler.cs | 73 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 _ActiveRagdoll/RotationHandler.cs (limited to '_ActiveRagdoll/RotationHandler.cs') diff --git a/_ActiveRagdoll/RotationHandler.cs b/_ActiveRagdoll/RotationHandler.cs new file mode 100644 index 0000000..ee33545 --- /dev/null +++ b/_ActiveRagdoll/RotationHandler.cs @@ -0,0 +1,73 @@ +using UnityEngine; + +public class RotationHandler : MonoBehaviour +{ + private Transform rotationTarget; + + private Rigidbody hip; + + private Rigidbody torso; + + private Rigidbody head; + + public float rotationTorque; + + public float clamp; + + private InputHandler input; + + private PlayerDeath death; + + [HideInInspector] + public float hipCorrectionAmount; + + public bool useHip = true; + + public bool useTorso = true; + + public bool useHead = true; + + private void Start() + { + death = GetComponent(); + rotationTarget = GetComponentInChildren().transform; + hip = GetComponentInChildren().GetComponent(); + torso = GetComponentInChildren().GetComponent(); + head = GetComponentInChildren().GetComponent(); + input = GetComponent(); + } + + private void FixedUpdate() + { + if (!death.dead) + { + float num = head.transform.InverseTransformPoint(rotationTarget.position).x; + float num2 = torso.transform.InverseTransformPoint(rotationTarget.position).x; + hipCorrectionAmount = hip.transform.InverseTransformPoint(hip.transform.position + input.lastInputDirection * 10f).x; + float muscleFunction = death.muscleFunction; + float num3 = 0.3f; + if (input.inputMovementDirection.magnitude > 0.1f) + { + num3 = 1f; + } + if (clamp != 0f) + { + hipCorrectionAmount = Mathf.Clamp(hipCorrectionAmount, 0f - clamp, clamp); + num = Mathf.Clamp(num, 0f - clamp, clamp); + num2 = Mathf.Clamp(num2, 0f - clamp, clamp); + } + if (useHip) + { + hip.AddTorque(Vector3.up * muscleFunction * rotationTorque * num3 * hipCorrectionAmount, ForceMode.Acceleration); + } + if (useTorso) + { + torso.AddTorque(Vector3.up * muscleFunction * rotationTorque * num2, ForceMode.Acceleration); + } + if (useHead) + { + head.AddTorque(Vector3.up * muscleFunction * rotationTorque * num, ForceMode.Acceleration); + } + } + } +} -- cgit v1.1-26-g67d0