summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll
diff options
context:
space:
mode:
Diffstat (limited to '_ActiveRagdoll')
-rw-r--r--_ActiveRagdoll/AddForceByCollision.cs34
-rw-r--r--_ActiveRagdoll/AddForceToTarget.cs26
-rw-r--r--_ActiveRagdoll/AnimationObject.cs140
-rw-r--r--_ActiveRagdoll/BodyParts/HandLeft.cs (renamed from _ActiveRagdoll/HandLeft.cs)0
-rw-r--r--_ActiveRagdoll/BodyParts/HandRight.cs (renamed from _ActiveRagdoll/HandRight.cs)0
-rw-r--r--_ActiveRagdoll/BodyParts/Head.cs (renamed from _ActiveRagdoll/Head.cs)0
-rw-r--r--_ActiveRagdoll/BodyParts/Hip.cs (renamed from _ActiveRagdoll/Hip.cs)0
7 files changed, 200 insertions, 0 deletions
diff --git a/_ActiveRagdoll/AddForceByCollision.cs b/_ActiveRagdoll/AddForceByCollision.cs
new file mode 100644
index 0000000..8392efa
--- /dev/null
+++ b/_ActiveRagdoll/AddForceByCollision.cs
@@ -0,0 +1,34 @@
+using UnityEngine;
+
+public class AddForceByCollision : MonoBehaviour
+{
+ public Rigidbody rig;
+
+ public float amout;
+
+ private void Start()
+ {
+ }
+
+ private void Update()
+ {
+ }
+
+ private void OnCollisionEnter(Collision collision)
+ {
+ Collide(collision);
+ }
+
+ private void OnCollisionStay(Collision collision)
+ {
+ Collide(collision);
+ }
+
+ private void Collide(Collision collision)
+ {
+ if (collision.gameObject.layer == 9)
+ {
+ rig.AddForce(collision.contacts[0].normal * collision.impactForceSum.magnitude * amout, ForceMode.Acceleration);
+ }
+ }
+}
diff --git a/_ActiveRagdoll/AddForceToTarget.cs b/_ActiveRagdoll/AddForceToTarget.cs
new file mode 100644
index 0000000..9464c97
--- /dev/null
+++ b/_ActiveRagdoll/AddForceToTarget.cs
@@ -0,0 +1,26 @@
+using UnityEngine;
+
+public class AddForceToTarget : MonoBehaviour
+{
+ public AnimationCurve forceByRangeCurve;
+
+ public Rigidbody target;
+
+ public float force;
+
+ private Transform head;
+
+ private void Start()
+ {
+ head = GetComponentInChildren<Head>().transform;
+ }
+
+ private void FixedUpdate()
+ {
+ float num = forceByRangeCurve.Evaluate(Vector3.Distance(head.position, target.position)) * force;
+ if (num > 0f)
+ {
+ target.AddForce((head.position - target.position).normalized * num, ForceMode.Force);
+ }
+ }
+}
diff --git a/_ActiveRagdoll/AnimationObject.cs b/_ActiveRagdoll/AnimationObject.cs
new file mode 100644
index 0000000..0c2d636
--- /dev/null
+++ b/_ActiveRagdoll/AnimationObject.cs
@@ -0,0 +1,140 @@
+using UnityEngine;
+using UnityEngine.Events;
+
+public class AnimationObject : MonoBehaviour
+{
+ public PhysicsAnimation[] animations;
+
+ private Rigidbody rig;
+
+ private StepHandler stepHandler;
+
+ private Transform hip;
+
+ public float smoothing;
+
+ public float multiplier = 1f;
+
+ private bool isCurrentlyLeft;
+
+ public bool isLeft;
+
+ public UnityEvent switchToForwardEvent;
+
+ public UnityEvent switchToBackwardsEvent;
+
+ public bool dontAnimateIfHoldingSomething;
+
+ private Holding holding;
+
+ private AnimationHandler animationHandler;
+
+ private PlayerDeath death;
+
+ private float muscleMultiplier = 1f;
+
+ private void Start()
+ {
+ animationHandler = base.transform.root.GetComponent<AnimationHandler>();
+ rig = GetComponent<Rigidbody>();
+ stepHandler = base.transform.root.GetComponent<StepHandler>();
+ holding = base.transform.root.GetComponent<Holding>();
+ death = base.transform.root.GetComponent<PlayerDeath>();
+ Hip componentInChildren = base.transform.root.GetComponentInChildren<Hip>();
+ if ((bool)componentInChildren)
+ {
+ hip = componentInChildren.transform;
+ }
+ }
+
+ private void FixedUpdate()
+ {
+ if ((bool)death)
+ {
+ if (death.muscleFunction < 0f)
+ {
+ return;
+ }
+ muscleMultiplier = death.muscleFunction;
+ }
+ if ((!holding || !dontAnimateIfHoldingSomething || !holding.heldObject) && animationHandler.animationState < animations.Length)
+ {
+ SetMultiplier();
+ AddTorque();
+ AddForce();
+ }
+ }
+
+ private void AddForce()
+ {
+ Vector3 vector = Vector3.zero;
+ if (isCurrentlyLeft == isLeft)
+ {
+ Vector3 forwardForce = animations[animationHandler.animationState].forwardForce;
+ if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World)
+ {
+ vector = forwardForce;
+ }
+ if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip)
+ {
+ vector = hip.TransformDirection(forwardForce);
+ }
+ }
+ else
+ {
+ Vector3 backwardsForce = animations[animationHandler.animationState].backwardsForce;
+ if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World)
+ {
+ vector = backwardsForce;
+ }
+ if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip)
+ {
+ vector = hip.TransformDirection(backwardsForce);
+ }
+ }
+ rig.AddForce(vector * muscleMultiplier * multiplier, ForceMode.Acceleration);
+ }
+
+ private void AddTorque()
+ {
+ Vector3 vector = ((isCurrentlyLeft != isLeft) ? hip.TransformDirection(animations[animationHandler.animationState].backwardsTorque) : hip.TransformDirection(animations[animationHandler.animationState].forwardTorque));
+ rig.AddTorque(vector * muscleMultiplier * multiplier, ForceMode.Acceleration);
+ }
+
+ private void SetMultiplier()
+ {
+ if (smoothing != 0f)
+ {
+ float b = 1f;
+ if (isCurrentlyLeft != stepHandler.isLeft)
+ {
+ b = 0f;
+ }
+ multiplier = Mathf.Lerp(multiplier, b, 1f / smoothing);
+ if (multiplier < 0.1f)
+ {
+ ChangeStep();
+ }
+ }
+ else
+ {
+ ChangeStep();
+ }
+ }
+
+ private void ChangeStep()
+ {
+ if (isCurrentlyLeft != stepHandler.isLeft)
+ {
+ if (stepHandler.isLeft == isLeft)
+ {
+ switchToForwardEvent.Invoke();
+ }
+ else
+ {
+ switchToBackwardsEvent.Invoke();
+ }
+ isCurrentlyLeft = stepHandler.isLeft;
+ }
+ }
+}
diff --git a/_ActiveRagdoll/HandLeft.cs b/_ActiveRagdoll/BodyParts/HandLeft.cs
index 5f92108..5f92108 100644
--- a/_ActiveRagdoll/HandLeft.cs
+++ b/_ActiveRagdoll/BodyParts/HandLeft.cs
diff --git a/_ActiveRagdoll/HandRight.cs b/_ActiveRagdoll/BodyParts/HandRight.cs
index cb78d06..cb78d06 100644
--- a/_ActiveRagdoll/HandRight.cs
+++ b/_ActiveRagdoll/BodyParts/HandRight.cs
diff --git a/_ActiveRagdoll/Head.cs b/_ActiveRagdoll/BodyParts/Head.cs
index ce81442..ce81442 100644
--- a/_ActiveRagdoll/Head.cs
+++ b/_ActiveRagdoll/BodyParts/Head.cs
diff --git a/_ActiveRagdoll/Hip.cs b/_ActiveRagdoll/BodyParts/Hip.cs
index 379fb1d..379fb1d 100644
--- a/_ActiveRagdoll/Hip.cs
+++ b/_ActiveRagdoll/BodyParts/Hip.cs