diff options
author | chai <215380520@qq.com> | 2024-04-15 21:05:01 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-04-15 21:05:01 +0800 |
commit | 0464810f2f83c86560c3422d664380d474cb3e56 (patch) | |
tree | 3548bec2d39f6e2a9803dd02dd2f636922ea07c7 /ActiveRagdoll/Assets/TABG/Scripts | |
parent | f34c222b242c6fd01ed209ff827c614621160048 (diff) |
*misc
Diffstat (limited to 'ActiveRagdoll/Assets/TABG/Scripts')
7 files changed, 120 insertions, 51 deletions
diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/MovementDataHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/MovementDataHandler.cs index 9a87817..073ecbd 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/MovementDataHandler.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/MovementDataHandler.cs @@ -1,3 +1,6 @@ +using Rigging.BodyPart; +using Rigging.Debugging; +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -6,16 +9,48 @@ namespace Rigging.Data { public class MovementDataHandler : RiggingDataBase { - // Start is called before the first frame update - void Start() + + [HideInInspector, NonSerialized] + public Vector3 groundedForward; + + [HideInInspector, NonSerialized] + public Vector3 right; + + [HideInInspector, NonSerialized] + public Vector3 left; + + [HideInInspector, NonSerialized] + public Vector3 groundedBack; + + [HideInInspector, NonSerialized] + public float sinceJump = 1f; + + [HideInInspector, NonSerialized] + public float slopeStrenght; + + public Transform rotationTarget; + + private Rigging.BodyPart.Hip hip; + + protected override void OnStart() { - + base.OnStart(); + + hip = player.body.hip; } - // Update is called once per frame - void Update() + private void Update() { - + sinceJump += Time.deltaTime; + groundedForward = rotationTarget.forward; + groundedForward.y = slopeStrenght * 1f; + groundedForward = groundedForward.normalized; + groundedBack = -groundedForward; + right = rotationTarget.right; + left = -rotationTarget.right; + slopeStrenght = Mathf.Lerp(slopeStrenght, 0f, Time.deltaTime * 1f); + + GLHandle.DrawLine(hip.transform.position, hip.transform.position + groundedForward * 10f); } } diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs index 2afef1d..3a90eb6 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/SetAnimationByInput.cs @@ -5,9 +5,10 @@ using UnityEngine; namespace Rigging.Data { + [DisallowMultipleComponent] public class SetAnimationByInput : RiggingDataBase { - private InputHandler input; + private Rigging.Inputs.InputHandler input; private AnimationHandler anim; @@ -15,14 +16,32 @@ namespace Rigging.Data protected override void OnStart() { - input = player.status.input; + input = player.input; anim = player.status.animation; standingData = player.status.standingData; } private void Update() { - + if ((double)standingData.sinceGrounded > 0.2) + { + anim.animationState = 3; // jump + } + else if (input.inputMovementDirection.magnitude > 0.1f) + { + if (input.isSpringting) + { + anim.animationState = 1; // sprint + } + else + { + anim.animationState = 2; // run + } + } + else + { + anim.animationState = 0; // stand + } } } diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs index 7e673b1..e04ff0d 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Data/StepHandler.cs @@ -31,7 +31,7 @@ namespace Rigging.Data { leftLeg = player.body.legLeft.transform; rightLeg = player.body.legRight.transform; -// animationHandler = GetComponent<AnimationHandler>(); + animationHandler = player.status.animation; hip = player.body.hip.transform; } } diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Input/InputHandler.cs b/ActiveRagdoll/Assets/TABG/Scripts/Input/InputHandler.cs index bae645b..d32d67d 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Input/InputHandler.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Input/InputHandler.cs @@ -1,18 +1,60 @@ +using Rigging.Camera; +using Rigging.Data; +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Rendering; -public class InputHandler : MonoBehaviour +namespace Rigging.Inputs { - // Start is called before the first frame update - void Start() - { - - } - // Update is called once per frame - void Update() + public class InputHandler : MonoBehaviour { - + public Vector3 inputMovementDirection; + + public Vector3 lastInputDirection; + + public bool allowStrafe = true; + + private MovementDataHandler movementData; + + public bool isSpringting = false; + + private void Start() + { + movementData = GetComponentInChildren<MovementDataHandler>(); + } + + private void Update() + { + inputMovementDirection = Vector3.zero; + if (Input.GetKey(KeyCode.W)) + { + inputMovementDirection += movementData.groundedForward; + } + if (Input.GetKey(KeyCode.S)) + { + inputMovementDirection += movementData.groundedBack; + } + if (Input.GetKey(KeyCode.D) && allowStrafe) + { + inputMovementDirection += movementData.right; + } + if (Input.GetKey(KeyCode.A) && allowStrafe) + { + inputMovementDirection += movementData.left; + } + //if (Input.GetKey(KeyCode.LeftShift) && (!cameraMovement || !cameraMovement.ADS)) + //{ + // isSpringting = true; + //} + if (inputMovementDirection != Vector3.zero) + { + lastInputDirection = inputMovementDirection; + } + } + } + } diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Input/SetAnimationByInput.cs b/ActiveRagdoll/Assets/TABG/Scripts/Input/SetAnimationByInput.cs deleted file mode 100644 index 0f0feab..0000000 --- a/ActiveRagdoll/Assets/TABG/Scripts/Input/SetAnimationByInput.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class SetAnimationByInput : 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/Input/SetAnimationByInput.cs.meta b/ActiveRagdoll/Assets/TABG/Scripts/Input/SetAnimationByInput.cs.meta deleted file mode 100644 index 5f4a2de..0000000 --- a/ActiveRagdoll/Assets/TABG/Scripts/Input/SetAnimationByInput.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 01e4ef433b714c844acfa85d61aa6921 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/ActiveRagdoll/Assets/TABG/Scripts/Player.cs b/ActiveRagdoll/Assets/TABG/Scripts/Player.cs index b2168df..e07da7f 100644 --- a/ActiveRagdoll/Assets/TABG/Scripts/Player.cs +++ b/ActiveRagdoll/Assets/TABG/Scripts/Player.cs @@ -6,6 +6,7 @@ using Rigging.Action; using Rigging.Camera; using System; using Rigging.BodyPart; +using Rigging.Inputs; namespace Rigging { @@ -25,8 +26,6 @@ namespace Rigging public Strength strength; - public InputHandler input; - public AnimationHandler animation; } @@ -71,6 +70,8 @@ namespace Rigging public BodyParts body; + public Rigging.Inputs.InputHandler input; + private void Awake() { status = new Status(); @@ -80,7 +81,6 @@ namespace Rigging status.body = GetComponentInChildren<RigidbodyHolder>(); status.step = GetComponentInChildren<StepHandler>(); status.strength = GetComponentInChildren<Strength>(); - status.input = GetComponentInChildren<InputHandler>(); status.animation = GetComponentInChildren<AnimationHandler>(); actions = new Actions(); @@ -105,6 +105,8 @@ namespace Rigging body.legRight = GetComponentInChildren<Rigging.BodyPart.LegRight>(); body.torso = GetComponentInChildren<Rigging.BodyPart.Torso>(); + input = GetComponent<Rigging.Inputs.InputHandler>(); + } } |