diff options
11 files changed, 339 insertions, 92 deletions
diff --git a/ActiveRagdoll/Assets/TABG/Prefabs/human_rigging.prefab b/ActiveRagdoll/Assets/TABG/Prefabs/human_rigging.prefab index f82db40..aec59b7 100644 --- a/ActiveRagdoll/Assets/TABG/Prefabs/human_rigging.prefab +++ b/ActiveRagdoll/Assets/TABG/Prefabs/human_rigging.prefab @@ -1231,9 +1231,13 @@ MonoBehaviour: m_EditorClassIdentifier: staticCounter: 0 steps: - minTime: 0 - maxTime: 0 - minAngle: 0 + values: + - minTime: 0 + maxTime: 0 + minAngle: 0 + - minTime: 0 + maxTime: 0 + minAngle: 0 isLeft: 1 --- !u!114 &9141217467644992819 MonoBehaviour: @@ -1550,7 +1554,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -1856,7 +1861,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -3115,7 +3121,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -3649,7 +3656,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -3925,7 +3933,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -4154,7 +4163,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -4384,7 +4394,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -4645,7 +4656,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1f7b7bd465add9742bc770683eb2f98f, type: 3} m_Name: m_EditorClassIdentifier: - animations: [] + animations: + values: [] smoothing: 0 multiplier: 1 isLeft: 0 @@ -5087,8 +5099,14 @@ MonoBehaviour: footLeft: {fileID: 0} footRight: {fileID: 0} hip: {fileID: 0} - balanceForce: 50 - footCenterForces: 100 + balanceForces: + values: + - 50 + - 50 + footCenterForces: + values: + - 100 + - 100 --- !u!114 &4413022550555116497 MonoBehaviour: m_ObjectHideFlags: 0 @@ -5143,57 +5161,108 @@ MonoBehaviour: - rig: {fileID: 7724590171357447542} force: 150 offset: 0.95 - curve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 3 - time: 0.1818 - value: 1.2663 - inSlope: Infinity - outSlope: 0.010811341 - tangentMode: 71 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1.264 - value: 1.278 - inSlope: 0.010811341 - outSlope: 0 - tangentMode: 1 - weightedMode: 1 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1.3988 - value: 1.2757 - inSlope: 0 - outSlope: -0.2201391 - tangentMode: 65 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 1.5428 - value: 1.244 - inSlope: -0.2201391 - outSlope: -2.183764 - tangentMode: 69 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - - serializedVersion: 3 - time: 2.1033 - value: 0.02 - inSlope: -2.183764 - outSlope: 0 - tangentMode: 5 - weightedMode: 0 - inWeight: 0.33333334 - outWeight: 0.33333334 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 + curves: + values: + - serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0.1818 + value: 1.2663 + inSlope: Infinity + outSlope: 0.010811341 + tangentMode: 71 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.264 + value: 1.278 + inSlope: 0.010811341 + outSlope: 0 + tangentMode: 1 + weightedMode: 1 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.3988 + value: 1.2757 + inSlope: 0 + outSlope: -0.2201391 + tangentMode: 65 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.5428 + value: 1.244 + inSlope: -0.2201391 + outSlope: -2.183764 + tangentMode: 69 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 2.1033 + value: 0.02 + inSlope: -2.183764 + outSlope: 0 + tangentMode: 5 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + - serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0.1818 + value: 1.2663 + inSlope: Infinity + outSlope: 0.010811341 + tangentMode: 71 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.264 + value: 1.278 + inSlope: 0.010811341 + outSlope: 0 + tangentMode: 1 + weightedMode: 1 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.3988 + value: 1.2757 + inSlope: 0 + outSlope: -0.2201391 + tangentMode: 65 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1.5428 + value: 1.244 + inSlope: -0.2201391 + outSlope: -2.183764 + tangentMode: 69 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 2.1033 + value: 0.02 + inSlope: -2.183764 + outSlope: 0 + tangentMode: 5 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &9207913841552632399 GameObject: m_ObjectHideFlags: 0 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(); diff --git a/ActiveRagdoll/Assets/TABG/Test.unity b/ActiveRagdoll/Assets/TABG/Test.unity index 89951d6..f7f0b77 100644 --- a/ActiveRagdoll/Assets/TABG/Test.unity +++ b/ActiveRagdoll/Assets/TABG/Test.unity @@ -1091,6 +1091,11 @@ PrefabInstance: propertyPath: m_Name value: human_rigging objectReference: {fileID: 0} + - target: {fileID: 3805300644640191623, guid: fce18bbf37be1384eb1a089a94aac81d, + type: 3} + propertyPath: animationForceAmounts.values.Array.size + value: 2 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: fce18bbf37be1384eb1a089a94aac81d, type: 3} --- !u!1001 &8277099497161960097 |