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 --- CreepyRobots.csproj | 3 - GameMode.cs | 2 +- _ActiveRagdoll/Actions/Gravity.cs | 52 ++++ _ActiveRagdoll/Actions/Holding.cs | 289 +++++++++++++++++++++++ _ActiveRagdoll/Actions/PlayerDeath.cs | 126 ++++++++++ _ActiveRagdoll/Actions/PlayerKnockback.cs | 53 +++++ _ActiveRagdoll/Actions/SetAnimationByInput.cs | 41 ++++ _ActiveRagdoll/Actions/SetAnimationByVelocity.cs | 12 + _ActiveRagdoll/Actions/StayInPlace.cs | 51 ++++ _ActiveRagdoll/DragHandler.cs | 25 -- _ActiveRagdoll/FootHandler.cs | 75 ------ _ActiveRagdoll/Gravity.cs | 47 ---- _ActiveRagdoll/Handlers/AnimationHandler.cs | 9 +- _ActiveRagdoll/Handlers/DragHandler.cs | 26 ++ _ActiveRagdoll/Handlers/FootHandler.cs | 75 ++++++ _ActiveRagdoll/Handlers/HeadCollisionHandler.cs | 31 +++ _ActiveRagdoll/Handlers/RagdollHandler.cs | 21 ++ _ActiveRagdoll/Handlers/RigidbodyHolder.cs | 45 ++++ _ActiveRagdoll/Handlers/RotationHandler.cs | 73 ++++++ _ActiveRagdoll/Handlers/StandingDataHandler.cs | 69 ++++++ _ActiveRagdoll/Handlers/WeaponHandler.cs | 75 ++++++ _ActiveRagdoll/HasControl.cs | 3 +- _ActiveRagdoll/HeadCollisionHandler.cs | 31 --- _ActiveRagdoll/Holding.cs | 289 ----------------------- _ActiveRagdoll/PlayerDeath.cs | 125 ---------- _ActiveRagdoll/PlayerKnockback.cs | 52 ---- _ActiveRagdoll/RagdollHandler.cs | 21 -- _ActiveRagdoll/RigidbodyHolder.cs | 44 ---- _ActiveRagdoll/RotationHandler.cs | 73 ------ _ActiveRagdoll/SetAnimationByInput.cs | 40 ---- _ActiveRagdoll/SetAnimationByVelocity.cs | 12 - _ActiveRagdoll/SetRigidbodySettings.cs | 4 +- _ActiveRagdoll/StandingDataHandler.cs | 69 ------ _ActiveRagdoll/StayInPlace.cs | 50 ---- _ActiveRagdoll/WeaponHandler.cs | 75 ------ _Debug/REPL.cs | 28 ++- 36 files changed, 1067 insertions(+), 1049 deletions(-) create mode 100644 _ActiveRagdoll/Actions/Gravity.cs create mode 100644 _ActiveRagdoll/Actions/Holding.cs create mode 100644 _ActiveRagdoll/Actions/PlayerDeath.cs create mode 100644 _ActiveRagdoll/Actions/PlayerKnockback.cs create mode 100644 _ActiveRagdoll/Actions/SetAnimationByInput.cs create mode 100644 _ActiveRagdoll/Actions/SetAnimationByVelocity.cs create mode 100644 _ActiveRagdoll/Actions/StayInPlace.cs delete mode 100644 _ActiveRagdoll/DragHandler.cs delete mode 100644 _ActiveRagdoll/FootHandler.cs delete mode 100644 _ActiveRagdoll/Gravity.cs create mode 100644 _ActiveRagdoll/Handlers/DragHandler.cs create mode 100644 _ActiveRagdoll/Handlers/FootHandler.cs create mode 100644 _ActiveRagdoll/Handlers/HeadCollisionHandler.cs create mode 100644 _ActiveRagdoll/Handlers/RagdollHandler.cs create mode 100644 _ActiveRagdoll/Handlers/RigidbodyHolder.cs create mode 100644 _ActiveRagdoll/Handlers/RotationHandler.cs create mode 100644 _ActiveRagdoll/Handlers/StandingDataHandler.cs create mode 100644 _ActiveRagdoll/Handlers/WeaponHandler.cs delete mode 100644 _ActiveRagdoll/HeadCollisionHandler.cs delete mode 100644 _ActiveRagdoll/Holding.cs delete mode 100644 _ActiveRagdoll/PlayerDeath.cs delete mode 100644 _ActiveRagdoll/PlayerKnockback.cs delete mode 100644 _ActiveRagdoll/RagdollHandler.cs delete mode 100644 _ActiveRagdoll/RigidbodyHolder.cs delete mode 100644 _ActiveRagdoll/RotationHandler.cs delete mode 100644 _ActiveRagdoll/SetAnimationByInput.cs delete mode 100644 _ActiveRagdoll/SetAnimationByVelocity.cs delete mode 100644 _ActiveRagdoll/StandingDataHandler.cs delete mode 100644 _ActiveRagdoll/StayInPlace.cs delete mode 100644 _ActiveRagdoll/WeaponHandler.cs diff --git a/CreepyRobots.csproj b/CreepyRobots.csproj index 4a8859f..4130888 100644 --- a/CreepyRobots.csproj +++ b/CreepyRobots.csproj @@ -180,9 +180,6 @@ ..\CreepyRobots_Data\Managed\UnityEngine.WindModule.dll - - - diff --git a/GameMode.cs b/GameMode.cs index 5b03929..5529231 100644 --- a/GameMode.cs +++ b/GameMode.cs @@ -30,7 +30,7 @@ public class GameMode : MonoBehaviour Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; - Invoke("DebugGame", 3); + Invoke("DebugGame", 1); Init(); while (true) 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); + } + } + } +} diff --git a/_ActiveRagdoll/Actions/Holding.cs b/_ActiveRagdoll/Actions/Holding.cs new file mode 100644 index 0000000..eb27095 --- /dev/null +++ b/_ActiveRagdoll/Actions/Holding.cs @@ -0,0 +1,289 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +//Player Holding 动作-拿武器 +public class Holding : MonoBehaviour +{ + [HideInInspector] + public HoldableObject heldObject; + + [HideInInspector] + public HoldableObject heldObjectOffHand; + + [HideInInspector] + public Transform baseTransform; + + private Rigidbody rightHand; + + private Rigidbody leftHand; + + [HideInInspector] + public ConfigurableJoint leftHandJoint; + + [HideInInspector] + public ConfigurableJoint rightHandJoint; + + public float grabForce; + + [HideInInspector] + public bool isGrabbing; + + private Transform rotaionTarget; + + private bool hasMainHandWeapon; + + private PlayerDeath death; + + public LayerMask mask = default(LayerMask); + + private Strength str; + + private float strength = 1f; + + private PID leftHandPID; + + private PID rightHandPID; + + private StandingDataHandler standingData; + + private void Awake() + { + death = GetComponent(); + standingData = GetComponent(); + str = GetComponent(); + if (!baseTransform) + { + baseTransform = GetComponentInChildren().transform; + } + rightHand = GetComponentInChildren().GetComponent(); + leftHand = GetComponentInChildren().GetComponent(); + rotaionTarget = base.transform.GetComponentInChildren().transform; + mask = LayerMask.GetMask("Map"); + leftHandPID = leftHand.GetComponent(); + rightHandPID = rightHand.GetComponent(); + } + + private void Update() + { + if (!death.dead && (bool)heldObject) + { + strength = str.strength; + if (((bool)rightHandJoint || !heldObject.rightHandPos) && ((bool)leftHandJoint || !heldObject.leftHandPos) && (!heldObjectOffHand || (((bool)rightHandJoint || !heldObjectOffHand.rightHandPos) && ((bool)leftHandJoint || !heldObjectOffHand.leftHandPos)))) + { + isGrabbing = false; + } + } + } + + private void FixedUpdate() + { + if (death.dead || isGrabbing) + { + return; + } + if ((bool)heldObject) + { + HoldObjectInPlace(heldObject.rig, heldObject, offHand: false, rightHand); + if (!heldObjectOffHand && (bool)leftHandJoint) + { + HoldObjectInPlace(heldObject.rig, heldObject, offHand: false, leftHand, justHand: true); + } + } + if ((bool)heldObjectOffHand) + { + HoldObjectInPlace(heldObjectOffHand.rig, heldObjectOffHand, offHand: true, leftHand); + } + } + + private void HoldObjectInPlace(Rigidbody rigi, HoldableObject held, bool offHand, Rigidbody hand, bool justHand = false) + { + Vector3 holdingPosition = held.holdingPosition; + if (offHand) + { + holdingPosition.x *= -1f; + } + holdingPosition = baseTransform.TransformPoint(holdingPosition); + Vector3 holdingRotation = held.holdingRotation; + Vector3 targetRotation = baseTransform.TransformDirection(holdingRotation); + Vector3 targetRotationUp = baseTransform.TransformDirection(held.holdingUpRotation); + if (!justHand) + { + held.pid.DoPID(holdingPosition, targetRotation, targetRotationUp, strength); + } + PID pID = rightHandPID; + Vector3 localPosition = held.rightHandPos.localPosition; + if (hand == leftHand) + { + localPosition = held.leftHandPos.localPosition; + pID = leftHandPID; + } + Vector3 position = held.holdingPosition + localPosition; + if (offHand) + { + position.x *= -1f; + } + position = baseTransform.TransformPoint(position); + Debug.DrawLine(position, position + Vector3.up); + Debug.DrawLine(holdingPosition, holdingPosition + Vector3.up); + pID.DoPID(position, Vector3.zero, Vector3.zero, strength); + } + + public void StartHolding(HoldableObject holdableObject, bool hasOffHand) + { + holdableObject.isHeld = true; + isGrabbing = true; + bool offHand = false; + if (!hasMainHandWeapon) + { + hasMainHandWeapon = true; + heldObject = holdableObject; + if ((bool)heldObject.rightHandPos) + { + StartCoroutine(Grab(mainHand: true, rightHand, heldObject, offHand: false)); + } + if ((bool)heldObject.leftHandPos && !hasOffHand) + { + StartCoroutine(Grab(mainHand: false, leftHand, heldObject, offHand: false)); + } + } + else + { + offHand = true; + heldObjectOffHand = holdableObject; + heldObjectOffHand.leftHandPos = heldObjectOffHand.rightHandPos; + if ((bool)heldObjectOffHand.rightHandPos) + { + StartCoroutine(Grab(mainHand: false, leftHand, heldObjectOffHand, offHand: true)); + } + } + StartCoroutine(HoldweaponStill(holdableObject.rig, offHand, holdableObject)); + } + + private IEnumerator Grab(bool mainHand, Rigidbody hand, HoldableObject held, bool offHand) + { + while (isGrabbing) + { + if (mainHand) + { + if (!rightHandJoint) + { + ReachForPoint(rightHand, rightHand.transform.GetChild(0).position, held.rightHandPos, isLeft: false, held.rig, held, offHand); + rightHand.GetComponentInChildren().enabled = false; + } + } + else if (!leftHandJoint) + { + ReachForPoint(leftHand, leftHand.transform.GetChild(0).position, held.leftHandPos, isLeft: true, held.rig, held, offHand); + leftHand.GetComponentInChildren().enabled = false; + } + yield return null; + } + leftHand.GetComponentInChildren().enabled = true; + rightHand.GetComponentInChildren().enabled = true; + } + + private IEnumerator HoldweaponStill(Rigidbody rigToGrab, bool offHand, HoldableObject held) + { + while (isGrabbing) + { + Vector3 pos = held.holdingPosition; + if (offHand) + { + pos.x *= -1f; + } + rigToGrab.transform.position = baseTransform.TransformPoint(pos); + rigToGrab.transform.rotation = Quaternion.LookRotation(baseTransform.TransformDirection(heldObject.holdingRotation)); + yield return null; + } + } + + public void Drop() + { + List list = new List(); + if ((bool)heldObject) + { + list.Add(heldObject); + } + if ((bool)heldObjectOffHand) + { + list.Add(heldObjectOffHand); + } + for (int i = 0; i < list.Count; i++) + { + list[i].holder = null; + list[i].isHeld = false; + list[i].rig.useGravity = true; + list[i].rig.drag = 0f; + list[i].rig.angularDrag = 0f; + Collider[] componentsInChildren = list[i].GetComponentsInChildren(); + foreach (Collider collider in componentsInChildren) + { + collider.material = null; + } + } + heldObject = null; + heldObjectOffHand = null; + if ((bool)rightHandJoint) + { + Object.Destroy(rightHandJoint); + } + if ((bool)leftHandJoint) + { + Object.Destroy(leftHandJoint); + } + hasMainHandWeapon = false; + } + + private void ReachForPoint(Rigidbody rigToReach, Vector3 forcePosition, Transform targetPositionTransform, bool isLeft, Rigidbody rigToGrab, HoldableObject held, bool offHand) + { + Vector3 normalized = (targetPositionTransform.position - forcePosition).normalized; + rigToReach.AddForceAtPosition(normalized * grabForce * Mathf.Clamp(Time.deltaTime, 0f, 0.1f), forcePosition, ForceMode.Acceleration); + if (Vector3.Distance(targetPositionTransform.position, forcePosition) < 0.5f) + { + ConnectRig(rigToReach, rigToGrab, targetPositionTransform, isLeft, held, offHand); + } + } + + private void ConnectRig(Rigidbody startRig, Rigidbody targetRig, Transform targetPositionTransform, bool isLeft, HoldableObject held, bool offHand) + { + ConfigurableJoint configurableJoint = startRig.gameObject.AddComponent(); + if (offHand) + { + targetPositionTransform.localRotation = Quaternion.Euler(targetPositionTransform.localEulerAngles.x, 0f - targetPositionTransform.localEulerAngles.y, targetPositionTransform.localEulerAngles.z); + } + startRig.transform.rotation = targetPositionTransform.rotation; + startRig.transform.position += targetPositionTransform.position - startRig.transform.GetChild(0).position; + configurableJoint.connectedBody = targetRig; + configurableJoint.projectionMode = JointProjectionMode.PositionAndRotation; + configurableJoint.xMotion = ConfigurableJointMotion.Locked; + configurableJoint.yMotion = ConfigurableJointMotion.Locked; + configurableJoint.zMotion = ConfigurableJointMotion.Locked; + configurableJoint.angularXMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularYMotion = ConfigurableJointMotion.Limited; + configurableJoint.angularZMotion = ConfigurableJointMotion.Limited; + SoftJointLimit highAngularXLimit = configurableJoint.highAngularXLimit; + highAngularXLimit.limit = held.swingAngles.y; + configurableJoint.highAngularXLimit = highAngularXLimit; + highAngularXLimit.limit = held.swingAngles.x; + configurableJoint.lowAngularXLimit = highAngularXLimit; + highAngularXLimit.limit = held.twistAngles.x; + configurableJoint.angularYLimit = highAngularXLimit; + highAngularXLimit.limit = held.twistAngles.y; + configurableJoint.angularZLimit = highAngularXLimit; + SoftJointLimitSpring angularXLimitSpring = configurableJoint.angularXLimitSpring; + angularXLimitSpring.spring = held.swingSpring; + configurableJoint.angularXLimitSpring = angularXLimitSpring; + angularXLimitSpring.spring = held.twistSpring; + configurableJoint.angularYZLimitSpring = angularXLimitSpring; + configurableJoint.anchor = startRig.transform.InverseTransformPoint(startRig.transform.GetChild(0).position); + if (isLeft) + { + leftHandJoint = configurableJoint; + } + else + { + rightHandJoint = configurableJoint; + } + } +} diff --git a/_ActiveRagdoll/Actions/PlayerDeath.cs b/_ActiveRagdoll/Actions/PlayerDeath.cs new file mode 100644 index 0000000..637e713 --- /dev/null +++ b/_ActiveRagdoll/Actions/PlayerDeath.cs @@ -0,0 +1,126 @@ +using UnityEngine; + +//Player PlayerDeath 动作-角色死亡 +public class PlayerDeath : MonoBehaviour +{ + public bool dead; + + private bool isFrozen; + + public float muscleFunction = 1f; + + public bool terminalState; + + private DamageEffects damageEffects; + + private RagdollHandler ragdoll; + + private Transform hip; + + public float health = 100f; + + public ParticleSystem[] damageParticles; + + private HasControl hasControll; + + private Holding holding; + + private void Start() + { + damageEffects = GetComponent(); + ragdoll = GetComponent(); + hip = GetComponentInChildren().transform; + hasControll = GetComponent(); + holding = GetComponent(); + } + + private void Update() + { + if (health < 100f) + { + health += Time.deltaTime * 10f; + health = Mathf.Clamp(health, -10f, 100f); + } + if (hip.transform.position.y < -10f) + { + Die(); + } + if (terminalState && muscleFunction > 0f) + { + muscleFunction -= Time.deltaTime * 1f; + } + if (muscleFunction < 0f && !isFrozen) + { + FreezeBody(); + } + } + + public void TakeDamage(Vector3 damage, Vector3 hitPoint, Rigidbody hitRig = null) + { + if (hasControll.hasControl) + { + damageEffects.TakeDamage(damage, hitPoint); + } + if (hitPoint != Vector3.zero) + { + for (int i = 0; i < damageParticles.Length; i++) + { + damageParticles[i].transform.rotation = Quaternion.LookRotation(damage); + damageParticles[i].transform.position = hitPoint; + damageParticles[i].Play(); + } + } + health -= damage.magnitude; + if (!(health <= 0f)) + { + return; + } + if ((bool)hitRig) + { + ConfigurableJoint component = hitRig.GetComponent(); + if ((bool)component) + { + Object.Destroy(component); + } + } + Kill(); + } + + public void FreezeBody() + { + isFrozen = true; + Joint[] componentsInChildren = GetComponentsInChildren(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + ConfigurableJoint configurableJoint = (ConfigurableJoint)componentsInChildren[i]; + Rigidbody component = configurableJoint.GetComponent(); + JointDrive angularXDrive = configurableJoint.angularXDrive; + angularXDrive.positionSpring = 5f * component.mass; + angularXDrive.positionDamper = 1f * component.mass; + configurableJoint.angularXDrive = angularXDrive; + configurableJoint.angularYZDrive = angularXDrive; + configurableJoint.SetTargetRotationLocal(configurableJoint.transform.localRotation, configurableJoint.gameObject.GetComponent().startRotationLocal); + } + } + + public void Die() + { + if (!dead) + { + holding.Drop(); + dead = true; + ragdoll.ragdollValue = 0f; + Collider[] componentsInChildren = GetComponentsInChildren(); + foreach (Collider collider in componentsInChildren) + { + collider.material = null; + } + } + } + + public void Kill() + { + terminalState = true; + Die(); + } +} diff --git a/_ActiveRagdoll/Actions/PlayerKnockback.cs b/_ActiveRagdoll/Actions/PlayerKnockback.cs new file mode 100644 index 0000000..d4839bf --- /dev/null +++ b/_ActiveRagdoll/Actions/PlayerKnockback.cs @@ -0,0 +1,53 @@ +using UnityEngine; + +//Player PlayerKnockback 动作-击退 +public class PlayerKnockback : MonoBehaviour +{ + private RigidbodyHolder allRigs;//14 + + private StandingDataHandler standing; + + private WeaponHandler weapons; + + private void Start() + { + allRigs = GetComponent(); + standing = GetComponent(); + weapons = GetComponent(); + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.K)) //kill + { + AddSeriousKnockback(); + } + } + + public void AddForce(Vector3 force, Rigidbody rig) + { + if (force.magnitude > 200f) + { + AddSeriousKnockback(); + force *= 0.1f; + } + for (int i = 0; i < allRigs.GetAllRigs().Length; i++) + { + float num = 1f; + if (rig == allRigs.GetAllRigs()[i]) + { + num *= 1f; + } + allRigs.GetAllRigs()[i].AddForce(force * num * 20f, ForceMode.Acceleration); + } + } + + private void AddSeriousKnockback() + { + GetComponent().Kill(); + } + + private void AddNormalKnockback() + { + } +} diff --git a/_ActiveRagdoll/Actions/SetAnimationByInput.cs b/_ActiveRagdoll/Actions/SetAnimationByInput.cs new file mode 100644 index 0000000..41948ec --- /dev/null +++ b/_ActiveRagdoll/Actions/SetAnimationByInput.cs @@ -0,0 +1,41 @@ +using UnityEngine; + +//Player SetAnimationByInput 根据键盘输入切换动作 +public class SetAnimationByInput : MonoBehaviour +{ + private InputHandler input; + + private AnimationHandler anim; + + private StandingDataHandler standingData; + + private void Start() + { + anim = GetComponent(); + input = GetComponent(); + standingData = GetComponent(); + } + + private void Update() + { + if ((double)standingData.sinceGrounded > 0.2) + { + anim.animationState = 3; + } + else if (input.inputMovementDirection.magnitude > 0.1f) + { + if (input.isSpringting) + { + anim.animationState = 1; + } + else + { + anim.animationState = 2; + } + } + else + { + anim.animationState = 0; + } + } +} diff --git a/_ActiveRagdoll/Actions/SetAnimationByVelocity.cs b/_ActiveRagdoll/Actions/SetAnimationByVelocity.cs new file mode 100644 index 0000000..c737363 --- /dev/null +++ b/_ActiveRagdoll/Actions/SetAnimationByVelocity.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +public class SetAnimationByVelocity : MonoBehaviour +{ + private void Start() + { + } + + private void Update() + { + } +} diff --git a/_ActiveRagdoll/Actions/StayInPlace.cs b/_ActiveRagdoll/Actions/StayInPlace.cs new file mode 100644 index 0000000..c8bdf4b --- /dev/null +++ b/_ActiveRagdoll/Actions/StayInPlace.cs @@ -0,0 +1,51 @@ +using UnityEngine; + +//Player StayInPlace 动作-移动到停止时停下来 +public class StayInPlace : MonoBehaviour +{ + private InputHandler input; + + public Rigidbody rig; // Hip + + public float force;// 100 + + private Vector3 stopPosition; + + private bool isBroken; + + private PlayerDeath death; + + private Strength str; + + private float strength = 1f; + + private void Start() + { + str = GetComponent(); + input = GetComponent(); + death = GetComponent(); + stopPosition = rig.position; + } + + private void FixedUpdate() + { + if (death.dead) + { + return; + } + strength = str.strength; + if (input.inputMovementDirection.magnitude > 0.1f) // 移动 + { + stopPosition = rig.position + rig.velocity * 0.25f; + isBroken = false; + } + else if (!isBroken) // 移动到停下 + { + if (Vector3.Distance(stopPosition, rig.position) > 1f) + { + isBroken = true; + } + rig.AddForce((stopPosition - rig.position) * force * strength, ForceMode.Acceleration); + } + } +} diff --git a/_ActiveRagdoll/DragHandler.cs b/_ActiveRagdoll/DragHandler.cs deleted file mode 100644 index adb8df4..0000000 --- a/_ActiveRagdoll/DragHandler.cs +++ /dev/null @@ -1,25 +0,0 @@ -using UnityEngine; - -public class DragHandler : MonoBehaviour -{ - private float drag; - - private float angularDrag; - - private Rigidbody rig; - - public float dragAmount = 1f; - - private void Start() - { - rig = GetComponent(); - drag = rig.drag; - angularDrag = rig.angularDrag; - } - - private void Update() - { - rig.drag = drag * dragAmount; - rig.angularDrag = angularDrag * dragAmount; - } -} diff --git a/_ActiveRagdoll/FootHandler.cs b/_ActiveRagdoll/FootHandler.cs deleted file mode 100644 index 7343e21..0000000 --- a/_ActiveRagdoll/FootHandler.cs +++ /dev/null @@ -1,75 +0,0 @@ -using UnityEngine; - -public class FootHandler : MonoBehaviour -{ - private AnimationHandler animHandler; - - private Collider collider; - - public PhysicMaterial slippery; - - private PhysicMaterial footMaterial; - - private Transform torso; - - private MovementDataHandler moveData; - - private Rigidbody rig; - - private RotationHandler rot; - - private Vector3 rotationDif; - - private AnimationObject anim; - - private StepHandler handler; - - private void Start() - { - animHandler = base.transform.root.GetComponent(); - moveData = base.transform.root.GetComponent(); - collider = GetComponentInChildren(); - rig = GetComponent(); - footMaterial = collider.material; - torso = base.transform.root.GetComponentInChildren().transform; - rot = base.transform.root.GetComponent(); - handler = base.transform.root.GetComponent(); - anim = GetComponentInChildren(); - } - - private void Update() - { - float num = Mathf.Abs(torso.position.x - base.transform.position.x) + Mathf.Abs(torso.position.z - base.transform.position.z); - if (rot.hipCorrectionAmount > 30f || ((bool)anim && anim.isLeft != handler.isLeft)) - { - SetFoot(active: false); - } - else if (animHandler.animationState == 0) - { - if (num > 0.1f || rotationDif.magnitude > 15f) - { - SetFoot(active: false); - } - else - { - SetFoot(active: true); - } - } - else - { - SetFoot(active: true); - } - } - - private void FixedUpdate() - { - } - - private void SetFoot(bool active) - { - if (active) - { - collider.material = footMaterial; - } - } -} diff --git a/_ActiveRagdoll/Gravity.cs b/_ActiveRagdoll/Gravity.cs deleted file mode 100644 index f646f0c..0000000 --- a/_ActiveRagdoll/Gravity.cs +++ /dev/null @@ -1,47 +0,0 @@ -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); - } - } - } -} diff --git a/_ActiveRagdoll/Handlers/AnimationHandler.cs b/_ActiveRagdoll/Handlers/AnimationHandler.cs index 382b3a5..437a8dd 100644 --- a/_ActiveRagdoll/Handlers/AnimationHandler.cs +++ b/_ActiveRagdoll/Handlers/AnimationHandler.cs @@ -3,7 +3,14 @@ using UnityEngine; //Player AnimationHandler 记录当前动作状态编号 public class AnimationHandler : MonoBehaviour { - public int animationState; + /* + 0 Stand + 1 Sprint + 2 Run + 3 Jump + */ + + public int animationState; private void Start() { diff --git a/_ActiveRagdoll/Handlers/DragHandler.cs b/_ActiveRagdoll/Handlers/DragHandler.cs new file mode 100644 index 0000000..5f6556c --- /dev/null +++ b/_ActiveRagdoll/Handlers/DragHandler.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +// 设置当前骨骼的drag和angularDrag +public class DragHandler : MonoBehaviour +{ + private float drag; + + private float angularDrag; + + private Rigidbody rig; + + public float dragAmount = 1f; + + private void Start() + { + rig = GetComponent(); + drag = rig.drag; + angularDrag = rig.angularDrag; + } + + private void Update() + { + rig.drag = drag * dragAmount; + rig.angularDrag = angularDrag * dragAmount; + } +} diff --git a/_ActiveRagdoll/Handlers/FootHandler.cs b/_ActiveRagdoll/Handlers/FootHandler.cs new file mode 100644 index 0000000..7343e21 --- /dev/null +++ b/_ActiveRagdoll/Handlers/FootHandler.cs @@ -0,0 +1,75 @@ +using UnityEngine; + +public class FootHandler : MonoBehaviour +{ + private AnimationHandler animHandler; + + private Collider collider; + + public PhysicMaterial slippery; + + private PhysicMaterial footMaterial; + + private Transform torso; + + private MovementDataHandler moveData; + + private Rigidbody rig; + + private RotationHandler rot; + + private Vector3 rotationDif; + + private AnimationObject anim; + + private StepHandler handler; + + private void Start() + { + animHandler = base.transform.root.GetComponent(); + moveData = base.transform.root.GetComponent(); + collider = GetComponentInChildren(); + rig = GetComponent(); + footMaterial = collider.material; + torso = base.transform.root.GetComponentInChildren().transform; + rot = base.transform.root.GetComponent(); + handler = base.transform.root.GetComponent(); + anim = GetComponentInChildren(); + } + + private void Update() + { + float num = Mathf.Abs(torso.position.x - base.transform.position.x) + Mathf.Abs(torso.position.z - base.transform.position.z); + if (rot.hipCorrectionAmount > 30f || ((bool)anim && anim.isLeft != handler.isLeft)) + { + SetFoot(active: false); + } + else if (animHandler.animationState == 0) + { + if (num > 0.1f || rotationDif.magnitude > 15f) + { + SetFoot(active: false); + } + else + { + SetFoot(active: true); + } + } + else + { + SetFoot(active: true); + } + } + + private void FixedUpdate() + { + } + + private void SetFoot(bool active) + { + if (active) + { + collider.material = footMaterial; + } + } +} diff --git a/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs b/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs new file mode 100644 index 0000000..c929f0e --- /dev/null +++ b/_ActiveRagdoll/Handlers/HeadCollisionHandler.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +public class HeadCollisionHandler : MonoBehaviour +{ + public float collisionValue; + + private void Start() + { + } + + private void Update() + { + collisionValue = Mathf.Lerp(collisionValue, 0f, Time.deltaTime * 6f); + } + + private void OnCollisionEnter(Collision collision) + { + if (!(collision.transform.root == base.transform.root)) + { + collisionValue += collision.relativeVelocity.magnitude * 0.5f; + } + } + + private void OnCollisionStay(Collision collision) + { + if (!(collision.transform.root == base.transform.root)) + { + collisionValue += collision.relativeVelocity.magnitude * 0.1f; + } + } +} diff --git a/_ActiveRagdoll/Handlers/RagdollHandler.cs b/_ActiveRagdoll/Handlers/RagdollHandler.cs new file mode 100644 index 0000000..29daa68 --- /dev/null +++ b/_ActiveRagdoll/Handlers/RagdollHandler.cs @@ -0,0 +1,21 @@ +using UnityEngine; + +public class RagdollHandler : MonoBehaviour +{ + public float ragdollValue = 1f;//1 + + private RigidbodyHolder rigs;//14 + + private void Start() + { + rigs = GetComponent(); + } + + private void Update() + { + for (int i = 0; i < rigs.GetAllRigs().Length; i++) + { + rigs.GetAllRigs()[i].GetComponent().dragAmount = ragdollValue; + } + } +} diff --git a/_ActiveRagdoll/Handlers/RigidbodyHolder.cs b/_ActiveRagdoll/Handlers/RigidbodyHolder.cs new file mode 100644 index 0000000..3ef0c54 --- /dev/null +++ b/_ActiveRagdoll/Handlers/RigidbodyHolder.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using UnityEngine; + +// 保存所有14个骨骼 +public class RigidbodyHolder : MonoBehaviour +{ + private Rigidbody[] allRigs; + + private WeaponHandler weapons; + + private void Start() + { + allRigs = GetComponentsInChildren(); + weapons = GetComponent(); + } + + private void Update() + { + } + + public Rigidbody[] GetAllRigs() + { + if (!weapons.leftGun && !weapons.rightGun) + { + return allRigs; + } + List list = new List(); + for (int i = 0; i < allRigs.Length; i++) + { + list.Add(allRigs[i]); + } + if ((bool)weapons) + { + if ((bool)weapons.leftGun) + { + list.Add(weapons.leftGun.rig); + } + if ((bool)weapons.rightGun) + { + list.Add(weapons.rightGun.rig); + } + } + return list.ToArray(); + } +} diff --git a/_ActiveRagdoll/Handlers/RotationHandler.cs b/_ActiveRagdoll/Handlers/RotationHandler.cs new file mode 100644 index 0000000..ee33545 --- /dev/null +++ b/_ActiveRagdoll/Handlers/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); + } + } + } +} diff --git a/_ActiveRagdoll/Handlers/StandingDataHandler.cs b/_ActiveRagdoll/Handlers/StandingDataHandler.cs new file mode 100644 index 0000000..a72ec09 --- /dev/null +++ b/_ActiveRagdoll/Handlers/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(); + knockback = GetComponent(); + } + + private void FixedUpdate() + { + sinceGrounded += Time.fixedDeltaTime; + sinceLanded += Time.fixedDeltaTime; + moveMentData = GetComponent(); + 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; + } +} diff --git a/_ActiveRagdoll/Handlers/WeaponHandler.cs b/_ActiveRagdoll/Handlers/WeaponHandler.cs new file mode 100644 index 0000000..7b3d80f --- /dev/null +++ b/_ActiveRagdoll/Handlers/WeaponHandler.cs @@ -0,0 +1,75 @@ +using UnityEngine; + +public class WeaponHandler : MonoBehaviour +{ + [HideInInspector] + public Gun leftGun; + + [HideInInspector] + public Gun rightGun; + + [HideInInspector] + public Transform gunADS; + + [HideInInspector] + public float ADSFOV; + + public bool isDualWeilding; + + private void Start() + { + } + + private void Update() + { + } + + public void SetWeapon(Weapon w, bool mainHand) + { + } + + public void SetGun(Gun g, bool mainHand) + { + if (mainHand) + { + rightGun = g; + gunADS = g.GetComponentInChildren().transform; + ADSFOV = g.ADSFOV; + } + else + { + leftGun = g; + } + if ((bool)leftGun && (bool)rightGun) + { + isDualWeilding = true; + } + } + + public void HoldAttack(bool shootWithRightGun, bool ADS) + { + if (shootWithRightGun) + { + if (rightGun.auto) + { + rightGun.Shoot(base.transform.root, ADS); + } + } + else if (leftGun.auto) + { + leftGun.Shoot(base.transform.root, ADS); + } + } + + public void PressAttack(bool shootWithRightGun, bool ADS) + { + if (shootWithRightGun) + { + rightGun.Shoot(base.transform.root, ADS); + } + else + { + leftGun.Shoot(base.transform.root, ADS); + } + } +} diff --git a/_ActiveRagdoll/HasControl.cs b/_ActiveRagdoll/HasControl.cs index dde8ad6..0759eb1 100644 --- a/_ActiveRagdoll/HasControl.cs +++ b/_ActiveRagdoll/HasControl.cs @@ -1,10 +1,11 @@ using UnityEngine; +// 批量控制某些go的显示和隐藏 public class HasControl : MonoBehaviour { public bool hasControl = true; - public GameObject[] objectsToRemove; + public GameObject[] objectsToRemove;//MainCamera ScreenShake private void Awake() { diff --git a/_ActiveRagdoll/HeadCollisionHandler.cs b/_ActiveRagdoll/HeadCollisionHandler.cs deleted file mode 100644 index c929f0e..0000000 --- a/_ActiveRagdoll/HeadCollisionHandler.cs +++ /dev/null @@ -1,31 +0,0 @@ -using UnityEngine; - -public class HeadCollisionHandler : MonoBehaviour -{ - public float collisionValue; - - private void Start() - { - } - - private void Update() - { - collisionValue = Mathf.Lerp(collisionValue, 0f, Time.deltaTime * 6f); - } - - private void OnCollisionEnter(Collision collision) - { - if (!(collision.transform.root == base.transform.root)) - { - collisionValue += collision.relativeVelocity.magnitude * 0.5f; - } - } - - private void OnCollisionStay(Collision collision) - { - if (!(collision.transform.root == base.transform.root)) - { - collisionValue += collision.relativeVelocity.magnitude * 0.1f; - } - } -} diff --git a/_ActiveRagdoll/Holding.cs b/_ActiveRagdoll/Holding.cs deleted file mode 100644 index eb27095..0000000 --- a/_ActiveRagdoll/Holding.cs +++ /dev/null @@ -1,289 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -//Player Holding 动作-拿武器 -public class Holding : MonoBehaviour -{ - [HideInInspector] - public HoldableObject heldObject; - - [HideInInspector] - public HoldableObject heldObjectOffHand; - - [HideInInspector] - public Transform baseTransform; - - private Rigidbody rightHand; - - private Rigidbody leftHand; - - [HideInInspector] - public ConfigurableJoint leftHandJoint; - - [HideInInspector] - public ConfigurableJoint rightHandJoint; - - public float grabForce; - - [HideInInspector] - public bool isGrabbing; - - private Transform rotaionTarget; - - private bool hasMainHandWeapon; - - private PlayerDeath death; - - public LayerMask mask = default(LayerMask); - - private Strength str; - - private float strength = 1f; - - private PID leftHandPID; - - private PID rightHandPID; - - private StandingDataHandler standingData; - - private void Awake() - { - death = GetComponent(); - standingData = GetComponent(); - str = GetComponent(); - if (!baseTransform) - { - baseTransform = GetComponentInChildren().transform; - } - rightHand = GetComponentInChildren().GetComponent(); - leftHand = GetComponentInChildren().GetComponent(); - rotaionTarget = base.transform.GetComponentInChildren().transform; - mask = LayerMask.GetMask("Map"); - leftHandPID = leftHand.GetComponent(); - rightHandPID = rightHand.GetComponent(); - } - - private void Update() - { - if (!death.dead && (bool)heldObject) - { - strength = str.strength; - if (((bool)rightHandJoint || !heldObject.rightHandPos) && ((bool)leftHandJoint || !heldObject.leftHandPos) && (!heldObjectOffHand || (((bool)rightHandJoint || !heldObjectOffHand.rightHandPos) && ((bool)leftHandJoint || !heldObjectOffHand.leftHandPos)))) - { - isGrabbing = false; - } - } - } - - private void FixedUpdate() - { - if (death.dead || isGrabbing) - { - return; - } - if ((bool)heldObject) - { - HoldObjectInPlace(heldObject.rig, heldObject, offHand: false, rightHand); - if (!heldObjectOffHand && (bool)leftHandJoint) - { - HoldObjectInPlace(heldObject.rig, heldObject, offHand: false, leftHand, justHand: true); - } - } - if ((bool)heldObjectOffHand) - { - HoldObjectInPlace(heldObjectOffHand.rig, heldObjectOffHand, offHand: true, leftHand); - } - } - - private void HoldObjectInPlace(Rigidbody rigi, HoldableObject held, bool offHand, Rigidbody hand, bool justHand = false) - { - Vector3 holdingPosition = held.holdingPosition; - if (offHand) - { - holdingPosition.x *= -1f; - } - holdingPosition = baseTransform.TransformPoint(holdingPosition); - Vector3 holdingRotation = held.holdingRotation; - Vector3 targetRotation = baseTransform.TransformDirection(holdingRotation); - Vector3 targetRotationUp = baseTransform.TransformDirection(held.holdingUpRotation); - if (!justHand) - { - held.pid.DoPID(holdingPosition, targetRotation, targetRotationUp, strength); - } - PID pID = rightHandPID; - Vector3 localPosition = held.rightHandPos.localPosition; - if (hand == leftHand) - { - localPosition = held.leftHandPos.localPosition; - pID = leftHandPID; - } - Vector3 position = held.holdingPosition + localPosition; - if (offHand) - { - position.x *= -1f; - } - position = baseTransform.TransformPoint(position); - Debug.DrawLine(position, position + Vector3.up); - Debug.DrawLine(holdingPosition, holdingPosition + Vector3.up); - pID.DoPID(position, Vector3.zero, Vector3.zero, strength); - } - - public void StartHolding(HoldableObject holdableObject, bool hasOffHand) - { - holdableObject.isHeld = true; - isGrabbing = true; - bool offHand = false; - if (!hasMainHandWeapon) - { - hasMainHandWeapon = true; - heldObject = holdableObject; - if ((bool)heldObject.rightHandPos) - { - StartCoroutine(Grab(mainHand: true, rightHand, heldObject, offHand: false)); - } - if ((bool)heldObject.leftHandPos && !hasOffHand) - { - StartCoroutine(Grab(mainHand: false, leftHand, heldObject, offHand: false)); - } - } - else - { - offHand = true; - heldObjectOffHand = holdableObject; - heldObjectOffHand.leftHandPos = heldObjectOffHand.rightHandPos; - if ((bool)heldObjectOffHand.rightHandPos) - { - StartCoroutine(Grab(mainHand: false, leftHand, heldObjectOffHand, offHand: true)); - } - } - StartCoroutine(HoldweaponStill(holdableObject.rig, offHand, holdableObject)); - } - - private IEnumerator Grab(bool mainHand, Rigidbody hand, HoldableObject held, bool offHand) - { - while (isGrabbing) - { - if (mainHand) - { - if (!rightHandJoint) - { - ReachForPoint(rightHand, rightHand.transform.GetChild(0).position, held.rightHandPos, isLeft: false, held.rig, held, offHand); - rightHand.GetComponentInChildren().enabled = false; - } - } - else if (!leftHandJoint) - { - ReachForPoint(leftHand, leftHand.transform.GetChild(0).position, held.leftHandPos, isLeft: true, held.rig, held, offHand); - leftHand.GetComponentInChildren().enabled = false; - } - yield return null; - } - leftHand.GetComponentInChildren().enabled = true; - rightHand.GetComponentInChildren().enabled = true; - } - - private IEnumerator HoldweaponStill(Rigidbody rigToGrab, bool offHand, HoldableObject held) - { - while (isGrabbing) - { - Vector3 pos = held.holdingPosition; - if (offHand) - { - pos.x *= -1f; - } - rigToGrab.transform.position = baseTransform.TransformPoint(pos); - rigToGrab.transform.rotation = Quaternion.LookRotation(baseTransform.TransformDirection(heldObject.holdingRotation)); - yield return null; - } - } - - public void Drop() - { - List list = new List(); - if ((bool)heldObject) - { - list.Add(heldObject); - } - if ((bool)heldObjectOffHand) - { - list.Add(heldObjectOffHand); - } - for (int i = 0; i < list.Count; i++) - { - list[i].holder = null; - list[i].isHeld = false; - list[i].rig.useGravity = true; - list[i].rig.drag = 0f; - list[i].rig.angularDrag = 0f; - Collider[] componentsInChildren = list[i].GetComponentsInChildren(); - foreach (Collider collider in componentsInChildren) - { - collider.material = null; - } - } - heldObject = null; - heldObjectOffHand = null; - if ((bool)rightHandJoint) - { - Object.Destroy(rightHandJoint); - } - if ((bool)leftHandJoint) - { - Object.Destroy(leftHandJoint); - } - hasMainHandWeapon = false; - } - - private void ReachForPoint(Rigidbody rigToReach, Vector3 forcePosition, Transform targetPositionTransform, bool isLeft, Rigidbody rigToGrab, HoldableObject held, bool offHand) - { - Vector3 normalized = (targetPositionTransform.position - forcePosition).normalized; - rigToReach.AddForceAtPosition(normalized * grabForce * Mathf.Clamp(Time.deltaTime, 0f, 0.1f), forcePosition, ForceMode.Acceleration); - if (Vector3.Distance(targetPositionTransform.position, forcePosition) < 0.5f) - { - ConnectRig(rigToReach, rigToGrab, targetPositionTransform, isLeft, held, offHand); - } - } - - private void ConnectRig(Rigidbody startRig, Rigidbody targetRig, Transform targetPositionTransform, bool isLeft, HoldableObject held, bool offHand) - { - ConfigurableJoint configurableJoint = startRig.gameObject.AddComponent(); - if (offHand) - { - targetPositionTransform.localRotation = Quaternion.Euler(targetPositionTransform.localEulerAngles.x, 0f - targetPositionTransform.localEulerAngles.y, targetPositionTransform.localEulerAngles.z); - } - startRig.transform.rotation = targetPositionTransform.rotation; - startRig.transform.position += targetPositionTransform.position - startRig.transform.GetChild(0).position; - configurableJoint.connectedBody = targetRig; - configurableJoint.projectionMode = JointProjectionMode.PositionAndRotation; - configurableJoint.xMotion = ConfigurableJointMotion.Locked; - configurableJoint.yMotion = ConfigurableJointMotion.Locked; - configurableJoint.zMotion = ConfigurableJointMotion.Locked; - configurableJoint.angularXMotion = ConfigurableJointMotion.Limited; - configurableJoint.angularYMotion = ConfigurableJointMotion.Limited; - configurableJoint.angularZMotion = ConfigurableJointMotion.Limited; - SoftJointLimit highAngularXLimit = configurableJoint.highAngularXLimit; - highAngularXLimit.limit = held.swingAngles.y; - configurableJoint.highAngularXLimit = highAngularXLimit; - highAngularXLimit.limit = held.swingAngles.x; - configurableJoint.lowAngularXLimit = highAngularXLimit; - highAngularXLimit.limit = held.twistAngles.x; - configurableJoint.angularYLimit = highAngularXLimit; - highAngularXLimit.limit = held.twistAngles.y; - configurableJoint.angularZLimit = highAngularXLimit; - SoftJointLimitSpring angularXLimitSpring = configurableJoint.angularXLimitSpring; - angularXLimitSpring.spring = held.swingSpring; - configurableJoint.angularXLimitSpring = angularXLimitSpring; - angularXLimitSpring.spring = held.twistSpring; - configurableJoint.angularYZLimitSpring = angularXLimitSpring; - configurableJoint.anchor = startRig.transform.InverseTransformPoint(startRig.transform.GetChild(0).position); - if (isLeft) - { - leftHandJoint = configurableJoint; - } - else - { - rightHandJoint = configurableJoint; - } - } -} diff --git a/_ActiveRagdoll/PlayerDeath.cs b/_ActiveRagdoll/PlayerDeath.cs deleted file mode 100644 index ec0813a..0000000 --- a/_ActiveRagdoll/PlayerDeath.cs +++ /dev/null @@ -1,125 +0,0 @@ -using UnityEngine; - -public class PlayerDeath : MonoBehaviour -{ - public bool dead; - - private bool isFrozen; - - public float muscleFunction = 1f; - - public bool terminalState; - - private DamageEffects damageEffects; - - private RagdollHandler ragdoll; - - private Transform hip; - - public float health = 100f; - - public ParticleSystem[] damageParticles; - - private HasControl hasControll; - - private Holding holding; - - private void Start() - { - damageEffects = GetComponent(); - ragdoll = GetComponent(); - hip = GetComponentInChildren().transform; - hasControll = GetComponent(); - holding = GetComponent(); - } - - private void Update() - { - if (health < 100f) - { - health += Time.deltaTime * 10f; - health = Mathf.Clamp(health, -10f, 100f); - } - if (hip.transform.position.y < -10f) - { - Die(); - } - if (terminalState && muscleFunction > 0f) - { - muscleFunction -= Time.deltaTime * 1f; - } - if (muscleFunction < 0f && !isFrozen) - { - FreezeBody(); - } - } - - public void TakeDamage(Vector3 damage, Vector3 hitPoint, Rigidbody hitRig = null) - { - if (hasControll.hasControl) - { - damageEffects.TakeDamage(damage, hitPoint); - } - if (hitPoint != Vector3.zero) - { - for (int i = 0; i < damageParticles.Length; i++) - { - damageParticles[i].transform.rotation = Quaternion.LookRotation(damage); - damageParticles[i].transform.position = hitPoint; - damageParticles[i].Play(); - } - } - health -= damage.magnitude; - if (!(health <= 0f)) - { - return; - } - if ((bool)hitRig) - { - ConfigurableJoint component = hitRig.GetComponent(); - if ((bool)component) - { - Object.Destroy(component); - } - } - Kill(); - } - - public void FreezeBody() - { - isFrozen = true; - Joint[] componentsInChildren = GetComponentsInChildren(); - for (int i = 0; i < componentsInChildren.Length; i++) - { - ConfigurableJoint configurableJoint = (ConfigurableJoint)componentsInChildren[i]; - Rigidbody component = configurableJoint.GetComponent(); - JointDrive angularXDrive = configurableJoint.angularXDrive; - angularXDrive.positionSpring = 5f * component.mass; - angularXDrive.positionDamper = 1f * component.mass; - configurableJoint.angularXDrive = angularXDrive; - configurableJoint.angularYZDrive = angularXDrive; - configurableJoint.SetTargetRotationLocal(configurableJoint.transform.localRotation, configurableJoint.gameObject.GetComponent().startRotationLocal); - } - } - - public void Die() - { - if (!dead) - { - holding.Drop(); - dead = true; - ragdoll.ragdollValue = 0f; - Collider[] componentsInChildren = GetComponentsInChildren(); - foreach (Collider collider in componentsInChildren) - { - collider.material = null; - } - } - } - - public void Kill() - { - terminalState = true; - Die(); - } -} diff --git a/_ActiveRagdoll/PlayerKnockback.cs b/_ActiveRagdoll/PlayerKnockback.cs deleted file mode 100644 index 89fffb8..0000000 --- a/_ActiveRagdoll/PlayerKnockback.cs +++ /dev/null @@ -1,52 +0,0 @@ -using UnityEngine; - -public class PlayerKnockback : MonoBehaviour -{ - private RigidbodyHolder allRigs; - - private StandingDataHandler standing; - - private WeaponHandler weapons; - - private void Start() - { - allRigs = GetComponent(); - standing = GetComponent(); - weapons = GetComponent(); - } - - private void Update() - { - if (Input.GetKeyDown(KeyCode.K)) - { - AddSeriousKnockback(); - } - } - - public void AddForce(Vector3 force, Rigidbody rig) - { - if (force.magnitude > 200f) - { - AddSeriousKnockback(); - force *= 0.1f; - } - for (int i = 0; i < allRigs.GetAllRigs().Length; i++) - { - float num = 1f; - if (rig == allRigs.GetAllRigs()[i]) - { - num *= 1f; - } - allRigs.GetAllRigs()[i].AddForce(force * num * 20f, ForceMode.Acceleration); - } - } - - private void AddSeriousKnockback() - { - GetComponent().Kill(); - } - - private void AddNormalKnockback() - { - } -} diff --git a/_ActiveRagdoll/RagdollHandler.cs b/_ActiveRagdoll/RagdollHandler.cs deleted file mode 100644 index ca52b8d..0000000 --- a/_ActiveRagdoll/RagdollHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -using UnityEngine; - -public class RagdollHandler : MonoBehaviour -{ - public float ragdollValue = 1f; - - private RigidbodyHolder rigs; - - private void Start() - { - rigs = GetComponent(); - } - - private void Update() - { - for (int i = 0; i < rigs.GetAllRigs().Length; i++) - { - rigs.GetAllRigs()[i].GetComponent().dragAmount = ragdollValue; - } - } -} diff --git a/_ActiveRagdoll/RigidbodyHolder.cs b/_ActiveRagdoll/RigidbodyHolder.cs deleted file mode 100644 index 796f77a..0000000 --- a/_ActiveRagdoll/RigidbodyHolder.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -public class RigidbodyHolder : MonoBehaviour -{ - private Rigidbody[] allRigs; - - private WeaponHandler weapons; - - private void Start() - { - allRigs = GetComponentsInChildren(); - weapons = GetComponent(); - } - - private void Update() - { - } - - public Rigidbody[] GetAllRigs() - { - if (!weapons.leftGun && !weapons.rightGun) - { - return allRigs; - } - List list = new List(); - for (int i = 0; i < allRigs.Length; i++) - { - list.Add(allRigs[i]); - } - if ((bool)weapons) - { - if ((bool)weapons.leftGun) - { - list.Add(weapons.leftGun.rig); - } - if ((bool)weapons.rightGun) - { - list.Add(weapons.rightGun.rig); - } - } - return list.ToArray(); - } -} diff --git a/_ActiveRagdoll/RotationHandler.cs b/_ActiveRagdoll/RotationHandler.cs deleted file mode 100644 index ee33545..0000000 --- a/_ActiveRagdoll/RotationHandler.cs +++ /dev/null @@ -1,73 +0,0 @@ -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); - } - } - } -} diff --git a/_ActiveRagdoll/SetAnimationByInput.cs b/_ActiveRagdoll/SetAnimationByInput.cs deleted file mode 100644 index cc50e5a..0000000 --- a/_ActiveRagdoll/SetAnimationByInput.cs +++ /dev/null @@ -1,40 +0,0 @@ -using UnityEngine; - -public class SetAnimationByInput : MonoBehaviour -{ - private InputHandler input; - - private AnimationHandler anim; - - private StandingDataHandler standingData; - - private void Start() - { - anim = GetComponent(); - input = GetComponent(); - standingData = GetComponent(); - } - - private void Update() - { - if ((double)standingData.sinceGrounded > 0.2) - { - anim.animationState = 3; - } - else if (input.inputMovementDirection.magnitude > 0.1f) - { - if (input.isSpringting) - { - anim.animationState = 1; - } - else - { - anim.animationState = 2; - } - } - else - { - anim.animationState = 0; - } - } -} diff --git a/_ActiveRagdoll/SetAnimationByVelocity.cs b/_ActiveRagdoll/SetAnimationByVelocity.cs deleted file mode 100644 index c737363..0000000 --- a/_ActiveRagdoll/SetAnimationByVelocity.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEngine; - -public class SetAnimationByVelocity : MonoBehaviour -{ - private void Start() - { - } - - private void Update() - { - } -} diff --git a/_ActiveRagdoll/SetRigidbodySettings.cs b/_ActiveRagdoll/SetRigidbodySettings.cs index 2521b75..5f8695a 100644 --- a/_ActiveRagdoll/SetRigidbodySettings.cs +++ b/_ActiveRagdoll/SetRigidbodySettings.cs @@ -2,9 +2,9 @@ using UnityEngine; public class SetRigidbodySettings : MonoBehaviour { - public float maxAngular; + public float maxAngular;//1000 - private void Start() + private void Start() { Rigidbody[] componentsInChildren = GetComponentsInChildren(); foreach (Rigidbody rigidbody in componentsInChildren) diff --git a/_ActiveRagdoll/StandingDataHandler.cs b/_ActiveRagdoll/StandingDataHandler.cs deleted file mode 100644 index 10a1473..0000000 --- a/_ActiveRagdoll/StandingDataHandler.cs +++ /dev/null @@ -1,69 +0,0 @@ -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(); - knockback = GetComponent(); - } - - private void FixedUpdate() - { - sinceGrounded += Time.fixedDeltaTime; - sinceLanded += Time.fixedDeltaTime; - moveMentData = GetComponent(); - 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; - } -} diff --git a/_ActiveRagdoll/StayInPlace.cs b/_ActiveRagdoll/StayInPlace.cs deleted file mode 100644 index d10ebba..0000000 --- a/_ActiveRagdoll/StayInPlace.cs +++ /dev/null @@ -1,50 +0,0 @@ -using UnityEngine; - -public class StayInPlace : MonoBehaviour -{ - private InputHandler input; - - public Rigidbody rig; - - public float force; - - private Vector3 stopPosition; - - private bool isBroken; - - private PlayerDeath death; - - private Strength str; - - private float strength = 1f; - - private void Start() - { - str = GetComponent(); - input = GetComponent(); - death = GetComponent(); - stopPosition = rig.position; - } - - private void FixedUpdate() - { - if (death.dead) - { - return; - } - strength = str.strength; - if (input.inputMovementDirection.magnitude > 0.1f) - { - stopPosition = rig.position + rig.velocity * 0.25f; - isBroken = false; - } - else if (!isBroken) - { - if (Vector3.Distance(stopPosition, rig.position) > 1f) - { - isBroken = true; - } - rig.AddForce((stopPosition - rig.position) * force * strength, ForceMode.Acceleration); - } - } -} diff --git a/_ActiveRagdoll/WeaponHandler.cs b/_ActiveRagdoll/WeaponHandler.cs deleted file mode 100644 index 7b3d80f..0000000 --- a/_ActiveRagdoll/WeaponHandler.cs +++ /dev/null @@ -1,75 +0,0 @@ -using UnityEngine; - -public class WeaponHandler : MonoBehaviour -{ - [HideInInspector] - public Gun leftGun; - - [HideInInspector] - public Gun rightGun; - - [HideInInspector] - public Transform gunADS; - - [HideInInspector] - public float ADSFOV; - - public bool isDualWeilding; - - private void Start() - { - } - - private void Update() - { - } - - public void SetWeapon(Weapon w, bool mainHand) - { - } - - public void SetGun(Gun g, bool mainHand) - { - if (mainHand) - { - rightGun = g; - gunADS = g.GetComponentInChildren().transform; - ADSFOV = g.ADSFOV; - } - else - { - leftGun = g; - } - if ((bool)leftGun && (bool)rightGun) - { - isDualWeilding = true; - } - } - - public void HoldAttack(bool shootWithRightGun, bool ADS) - { - if (shootWithRightGun) - { - if (rightGun.auto) - { - rightGun.Shoot(base.transform.root, ADS); - } - } - else if (leftGun.auto) - { - leftGun.Shoot(base.transform.root, ADS); - } - } - - public void PressAttack(bool shootWithRightGun, bool ADS) - { - if (shootWithRightGun) - { - rightGun.Shoot(base.transform.root, ADS); - } - else - { - leftGun.Shoot(base.transform.root, ADS); - } - } -} diff --git a/_Debug/REPL.cs b/_Debug/REPL.cs index 5dd99e4..8e714ae 100644 --- a/_Debug/REPL.cs +++ b/_Debug/REPL.cs @@ -8,6 +8,8 @@ class REPL public static void StartREPL() { + //return; + AddHeightBox(); AddCamera(); AddRigidbodyDebug(); @@ -42,19 +44,19 @@ class REPL public static void AddRigidbodyDebug() { - string[] targets = { - //"Head", - //"Neck", - //"Torso", - //"Arm_Right", - //"Arm_Left", - //"Hand_Right", - //"Hand_Left", - //"Hip", - //"Leg_Left", - //"Leg_Right", - //"Foot_Left", - //"Foot_Right", + string[] targets = { + "Head", + "Neck", + "Torso", + "Arm_Right", + "Arm_Left", + "Hand_Right", + "Hand_Left", + "Hip", + "Leg_Left", + "Leg_Right", + "Foot_Left", + "Foot_Right", "Knee_Left", "Knee_Right", }; -- cgit v1.1-26-g67d0