summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/TABG/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'ActiveRagdoll/Assets/TABG/Scripts')
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Action/Balance.cs19
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs84
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Action/Standing.cs7
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs24
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs18
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs.meta11
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs32
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Data/RigidbodyHolder.cs27
-rw-r--r--ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs7
9 files changed, 201 insertions, 28 deletions
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Action/Balance.cs b/ActiveRagdoll/Assets/TABG/Scripts/Action/Balance.cs
index 2e25b68..a15d114 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Action/Balance.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Action/Balance.cs
@@ -27,9 +27,13 @@ namespace Rigging.Action
}
}
- public float balanceForce;
+ public AnimationParam<float> balanceForces;
- public float footCenterForces;
+ //public float balanceForce; //50
+
+ public AnimationParam<float> footCenterForces;
+
+ //public float footCenterForces;//100
private float muscleMultiplier; //1
@@ -42,6 +46,9 @@ namespace Rigging.Action
footLeft = player.body.kneeLeft.GetComponent<Rigidbody>();
footRight = player.body.kneeRight.GetComponent<Rigidbody>();
hip = player.body.hip.GetComponent<Rigidbody>();
+
+ footCenterForces.SetPlayer(player);
+ balanceForces.SetPlayer(player);
}
private void BalanceLegs()
@@ -73,8 +80,8 @@ namespace Rigging.Action
GLHandle.DrawLine(vector, vector + vector4);
GLHandle.DrawLine(vector2, vector2 + vector4);
- footLeft.AddForceAtPosition(vector4 * muscleMultiplier * crouchMultiplier * balanceForce, vector, ForceMode.Acceleration);
- footRight.AddForceAtPosition(vector4 * muscleMultiplier * crouchMultiplier * balanceForce, vector2, ForceMode.Acceleration);
+ footLeft.AddForceAtPosition(vector4 * muscleMultiplier * crouchMultiplier * balanceForces.current, vector, ForceMode.Acceleration);
+ footRight.AddForceAtPosition(vector4 * muscleMultiplier * crouchMultiplier * balanceForces.current, vector2, ForceMode.Acceleration);
}
}
@@ -95,7 +102,7 @@ namespace Rigging.Action
if (vector.y + 0.3f < hip.worldCenterOfMass.y)
{
vector3.y = 0f;
- footLeft.AddForceAtPosition((centerOfMass - vector3) * muscleMultiplier * footCenterForces, vector, ForceMode.Acceleration);
+ footLeft.AddForceAtPosition((centerOfMass - vector3) * muscleMultiplier * footCenterForces.current, vector, ForceMode.Acceleration);
GLHandle.DrawLine(vector, vector + (centerOfMass - vector3));
}
@@ -104,7 +111,7 @@ namespace Rigging.Action
if (vector4.y + 0.3f < hip.worldCenterOfMass.y)
{
vector4.y = 0f;
- footRight.AddForceAtPosition((centerOfMass - vector4) * muscleMultiplier * footCenterForces, vector2, ForceMode.Acceleration);
+ footRight.AddForceAtPosition((centerOfMass - vector4) * muscleMultiplier * footCenterForces.current, vector2, ForceMode.Acceleration);
GLHandle.DrawLine(vector2, vector2 + (centerOfMass - vector4));
}
}
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs b/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs
index 781e998..742ad29 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Action/Movement.cs
@@ -1,3 +1,5 @@
+using Rigging.Data;
+using Rigging.Inputs;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -7,7 +9,87 @@ namespace Rigging.Action
public class Movement : RiggingActionBase
{
-
+
+ private InputHandler inputHandler;
+
+ public float friction = 0.9f;
+
+ public Vector3 movementVector;
+
+ public AnimationParam<float> animationForceAmounts;
+
+ private AnimationHandler animationHandler;
+
+ private RigidbodyHolder allRigs;
+
+ public AnimationCurve jumpCurve;
+
+ public float jumpForce;
+
+ private StandingDataHandler standingData;
+
+ private MovementDataHandler data;
+
+ //private PlayerDeath death;
+
+ [HideInInspector]
+ public float multiplier = 1f;
+
+ //private WobbleShake wobbleShake;
+
+ protected override void OnStart()
+ {
+ animationForceAmounts.SetPlayer(player);
+ //wobbleShake = GetComponentInChildren<WobbleShake>();
+ //death = GetComponent<PlayerDeath>();
+ standingData = player.status.standingData;
+ inputHandler = player.input;
+ animationHandler = player.status.animation;
+ allRigs = player.status.body;
+ data = player.status.movementData;
+ }
+
+ private void FixedUpdate()
+ {
+ data.sinceJump += Time.fixedDeltaTime;
+ movementVector += inputHandler.inputMovementDirection * animationForceAmounts.current;
+ movementVector *= friction;
+ //for (int i = 0; i < allRigs.GetAllRigs().Length; i++)
+ //{
+ // allRigs.GetAllRigs()[i].AddForce(movementVector * multiplier, ForceMode.Acceleration);
+ //}
+ allRigs.AddForceToAll(movementVector * multiplier, ForceMode.Acceleration);
+ }
+
+ public void Jump()
+ {
+ if (!(data.sinceJump < 0.5f) && !(standingData.sinceGrounded > 0.3f))
+ {
+ data.sinceJump = 0f;
+ StartCoroutine(AddJumpForce());
+ //wobbleShake.AddShake(Vector3.up * 2f, 0.8f);
+ }
+ }
+
+ private IEnumerator AddJumpForce()
+ {
+ float counter = 0f;
+ //for (int i = 0; i < allRigs.GetAllRigs().Length; i++)
+ //{
+ // allRigs.GetAllRigs()[i].velocity = new Vector3(allRigs.GetAllRigs()[i].velocity.x, 0f, allRigs.GetAllRigs()[i].velocity.z);
+ //}
+ allRigs.ModifyVelocityForEach((_rig) => { return new Vector3(_rig.velocity.x, 0f, _rig.velocity.z); });
+ while (counter < jumpCurve.keys[jumpCurve.length - 1].time)
+ {
+ counter += Time.deltaTime;
+ //for (int j = 0; j < allRigs.GetAllRigs().Length; j++)
+ //{
+ // allRigs.GetAllRigs()[j].AddForce(Vector3.up * multiplier * jumpForce * jumpCurve.Evaluate(counter) * Time.deltaTime, ForceMode.Acceleration);
+ //}
+ allRigs.AddForceToAll(Vector3.up * multiplier * jumpForce * jumpCurve.Evaluate(counter) * Time.deltaTime, ForceMode.Acceleration);
+ yield return null;
+ }
+ }
}
} \ No newline at end of file
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Action/Standing.cs b/ActiveRagdoll/Assets/TABG/Scripts/Action/Standing.cs
index 2500de5..a4eefd8 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Action/Standing.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Action/Standing.cs
@@ -21,20 +21,19 @@ namespace Rigging.Action
private StandingDataHandler standingData;
- public AnimationCurve curve;
+ public AnimationParam<AnimationCurve> curves;
protected override void OnStart()
{
standingData = player.status.standingData;
-
+ curves.SetPlayer(player);
}
protected override void OnFixedUpdate()
{
- Stand(curve);
+ Stand(curves.current);
}
-
private void Stand(AnimationCurve curve)
{
//float num = 0f;
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs
index 9e9039f..b7ef84a 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/AnimationObject.cs
@@ -11,7 +11,7 @@ namespace Rigging.Animations
public class AnimationObject : MonoBehaviour
{
- public PhysicsAnimation[] animations;
+ public AnimationParam<PhysicsAnimation> animations;
private Rigidbody rig;
@@ -43,9 +43,9 @@ namespace Rigging.Animations
private void Start()
{
- animationHandler = base.transform.root.GetComponent<AnimationHandler>();
+ animationHandler = base.transform.root.GetComponentInChildren<AnimationHandler>();
rig = GetComponent<Rigidbody>();
- stepHandler = base.transform.root.GetComponent<StepHandler>();
+ stepHandler = base.transform.root.GetComponentInChildren<StepHandler>();
//holding = base.transform.root.GetComponent<Holding>();
//death = base.transform.root.GetComponent<PlayerDeath>();
Hip componentInChildren = base.transform.root.GetComponentInChildren<Hip>();
@@ -53,10 +53,14 @@ namespace Rigging.Animations
{
hip = componentInChildren.transform;
}
+
+ animations.SetPlayer(transform.root.GetComponent<Player>());
}
private void FixedUpdate()
{
+
+ return;
//if ((bool)death)
//{
// if (death.muscleFunction < 0f)
@@ -81,24 +85,24 @@ namespace Rigging.Animations
Vector3 vector = Vector3.zero;
if (isCurrentlyLeft == isLeft)
{
- Vector3 forwardForce = animations[animationHandler.animationState].forwardForce;
- if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World)
+ Vector3 forwardForce = animations.current.forwardForce;
+ if (animations.current.forceSpace == PhysicsAnimation.ForceSpace.World)
{
vector = forwardForce;
}
- if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip)
+ if (animations.current.forceSpace == PhysicsAnimation.ForceSpace.Hip)
{
vector = hip.TransformDirection(forwardForce);
}
}
else
{
- Vector3 backwardsForce = animations[animationHandler.animationState].backwardsForce;
- if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.World)
+ Vector3 backwardsForce = animations.current.backwardsForce;
+ if (animations.current.forceSpace == PhysicsAnimation.ForceSpace.World)
{
vector = backwardsForce;
}
- if (animations[animationHandler.animationState].forceSpace == PhysicsAnimation.ForceSpace.Hip)
+ if (animations.current.forceSpace == PhysicsAnimation.ForceSpace.Hip)
{
vector = hip.TransformDirection(backwardsForce);
}
@@ -108,7 +112,7 @@ namespace Rigging.Animations
private void AddTorque()
{
- Vector3 vector = ((isCurrentlyLeft != isLeft) ? hip.TransformDirection(animations[animationHandler.animationState].backwardsTorque) : hip.TransformDirection(animations[animationHandler.animationState].forwardTorque));
+ Vector3 vector = ((isCurrentlyLeft != isLeft) ? hip.TransformDirection(animations.current.backwardsTorque) : hip.TransformDirection(animations.current.forwardTorque));
rig.AddTorque(vector * muscleMultiplier * multiplier, ForceMode.Acceleration);
}
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs
new file mode 100644
index 0000000..44516ea
--- /dev/null
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs
@@ -0,0 +1,18 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class FootHandler : MonoBehaviour
+{
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+}
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs.meta
new file mode 100644
index 0000000..639fe22
--- /dev/null
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Animation/FootHandler.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 00a1a832fd188784190ab7eba313d3a0
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs
index 7a1a9f7..b581821 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/AnimationHandler.cs
@@ -15,7 +15,6 @@ namespace Rigging.Data
public string theString;
}
-
public class AnimationHandler : RiggingDataBase
{
/*
@@ -32,6 +31,37 @@ namespace Rigging.Data
{
animationState = newState;
}
+ }
+
+ [Serializable]
+ public class AnimationParam<T>
+ {
+ private Player player;
+
+ [SerializeField]
+ public T[] values;
+
+ public AnimationParam()
+ {
+ }
+
+ public void SetPlayer(Player p)
+ {
+ player = p;
+ }
+
+ public T CurrentValue()
+ {
+ return values[player.status.animation.animationState];
+ }
+
+ public T current
+ {
+ get
+ {
+ return values[player.status.animation.animationState];
+ }
+ }
}
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/RigidbodyHolder.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/RigidbodyHolder.cs
index eefa961..d1f01b1 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Data/RigidbodyHolder.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/RigidbodyHolder.cs
@@ -16,14 +16,35 @@ namespace Rigging.Data
allRigs = rootBone.gameObject.GetComponentsInChildren<Rigidbody>();
}
- private void Update()
+ public Rigidbody[] GetAllRigs()
{
+ return allRigs;
}
- public Rigidbody[] GetAllRigs()
+ public void AddForceToAll(Vector3 force, ForceMode mode)
{
- return allRigs;
+ for(int i = 0; i < allRigs.Length; ++i)
+ {
+ allRigs[i].AddForce(force, mode);
+ }
}
+
+ public void ModifyVelocityForEach(System.Func<Rigidbody, Vector3> modifier)
+ {
+ for (int i = 0; i < allRigs.Length; i++)
+ {
+ allRigs[i].velocity = modifier(allRigs[i]);
+ }
+ }
+
+ public void SetVelocityToAll(Vector3 vel)
+ {
+ for (int i = 0; i < allRigs.Length; i++)
+ {
+ allRigs[i].velocity = vel;
+ }
+ }
+
}
} \ No newline at end of file
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs
index f35f068..3caa488 100644
--- a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs
+++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs
@@ -11,7 +11,7 @@ namespace Rigging.Data
public float staticCounter;
- public Step steps;
+ public AnimationParam<Step> steps;
public bool isLeft;//左脚还是右脚在前面
@@ -34,6 +34,7 @@ namespace Rigging.Data
animationHandler = player.status.animation;
hip = player.body.hip.transform;
}
+ steps.SetPlayer(player);
}
protected override void OnUpdate()
@@ -46,8 +47,8 @@ namespace Rigging.Data
Switch();
}
}
- else if (counter > steps.minTime
- && (steps.minAngle == 0f || steps.minAngle < Vector3.Angle(leftLeg.forward, rightLeg.forward))
+ else if (counter > steps.current.minTime
+ && (steps.current.minAngle == 0f || steps.current.minAngle < Vector3.Angle(leftLeg.forward, rightLeg.forward))
&& isLeft == hip.InverseTransformPoint(leftLeg.position + leftLeg.forward).z > hip.InverseTransformPoint(rightLeg.position + rightLeg.forward).z)
{
Switch();