From 837bd1c85e17334e8c6c6ee287a900f2552668d4 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 29 Oct 2023 12:03:18 +0800 Subject: =?UTF-8?q?*=20=E7=A7=BB=E5=8A=A8legraycaster.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Doc/ROUNDS\345\210\206\346\236\220.xlsx" | Bin 9794388 -> 9854518 bytes ROUNDS/.vs/ROUNDS/v17/.suo | Bin 212480 -> 211968 bytes ROUNDS/LegRaycasters.cs | 78 -------------------- ROUNDS/_Player/LegRaycasters.cs | 79 +++++++++++++++++++++ .../bin/Debug/netstandard2.1/Assembly-CSharp.dll | Bin 902656 -> 909824 bytes .../bin/Debug/netstandard2.1/Assembly-CSharp.pdb | Bin 484060 -> 487200 bytes .../obj/Debug/netstandard2.1/Assembly-CSharp.dll | Bin 902656 -> 909824 bytes .../obj/Debug/netstandard2.1/Assembly-CSharp.pdb | Bin 484060 -> 487200 bytes 8 files changed, 79 insertions(+), 78 deletions(-) delete mode 100644 ROUNDS/LegRaycasters.cs create mode 100644 ROUNDS/_Player/LegRaycasters.cs diff --git "a/Doc/ROUNDS\345\210\206\346\236\220.xlsx" "b/Doc/ROUNDS\345\210\206\346\236\220.xlsx" index 752fca2..7771c84 100644 Binary files "a/Doc/ROUNDS\345\210\206\346\236\220.xlsx" and "b/Doc/ROUNDS\345\210\206\346\236\220.xlsx" differ diff --git a/ROUNDS/.vs/ROUNDS/v17/.suo b/ROUNDS/.vs/ROUNDS/v17/.suo index 1aa300a..2b412f9 100644 Binary files a/ROUNDS/.vs/ROUNDS/v17/.suo and b/ROUNDS/.vs/ROUNDS/v17/.suo differ diff --git a/ROUNDS/LegRaycasters.cs b/ROUNDS/LegRaycasters.cs deleted file mode 100644 index 704df1a..0000000 --- a/ROUNDS/LegRaycasters.cs +++ /dev/null @@ -1,78 +0,0 @@ -using UnityEngine; - -public class LegRaycasters : MonoBehaviour -{ - public LayerMask mask; - - public float force; - - public float drag; - - public Transform[] legCastPositions; - - public AnimationCurve animationCurve; - - private PlayerVelocity rig; - - private CharacterData data; - - public AnimationCurve wobbleCurve; - - public AnimationCurve forceCurve; - - private IkLeg[] legs; - - private float totalStepTime; - - private void Awake() - { - legs = base.transform.root.GetComponentsInChildren(); - } - - private void Start() - { - rig = GetComponentInParent(); - data = GetComponentInParent(); - } - - //! 重要,这个代码会让角色站在地面上,不会陷下去 - private void FixedUpdate() - { - totalStepTime = 0f; - for (int i = 0; i < legs.Length; i++) - { - if (!legs[i].footDown) - { - totalStepTime += legs[i].stepTime; - } - } - for (int j = 0; j < legCastPositions.Length; j++) - { - RaycastHit2D[] array = Physics2D.RaycastAll(legCastPositions[j].transform.position + Vector3.up * 0.5f, Vector2.down, 1f * base.transform.root.localScale.x, mask); - for (int k = 0; k < array.Length; k++) - { - if ((bool)array[k].transform && array[k].transform.root != base.transform.root) - { - HitGround(legCastPositions[j], array[k]); - break; - } - } - } - } - - private void HitGround(Transform leg, RaycastHit2D hit) - { - if (!(data.sinceJump < 0.2f) && !(Vector3.Angle(Vector3.up, hit.normal) > 70f)) - { - data.TouchGround(hit.point, hit.normal, hit.rigidbody); - Vector3 vector = ((Vector3)hit.point - leg.transform.position) / base.transform.root.localScale.x; - if (data.input.direction.x != 0f) - { - vector.y += wobbleCurve.Evaluate(totalStepTime) * base.transform.root.localScale.x; - rig.AddForce(Vector3.up * forceCurve.Evaluate(totalStepTime) * rig.mass); - } - rig.AddForce(animationCurve.Evaluate(Mathf.Abs(vector.y)) * Vector3.up * rig.mass * force); - rig.AddForce(animationCurve.Evaluate(Mathf.Abs(vector.y)) * (0f - rig.velocity.y) * Vector2.up * rig.mass * drag); - } - } -} diff --git a/ROUNDS/_Player/LegRaycasters.cs b/ROUNDS/_Player/LegRaycasters.cs new file mode 100644 index 0000000..4426342 --- /dev/null +++ b/ROUNDS/_Player/LegRaycasters.cs @@ -0,0 +1,79 @@ +using UnityEngine; + +public class LegRaycasters : MonoBehaviour +{ + public LayerMask mask; + + public float force; + + public float drag; + + public Transform[] legCastPositions; + + public AnimationCurve animationCurve; + + private PlayerVelocity rig; + + private CharacterData data; + + public AnimationCurve wobbleCurve; + + public AnimationCurve forceCurve; + + private IkLeg[] legs; + + private float totalStepTime; + + private void Awake() + { + legs = base.transform.root.GetComponentsInChildren(); + } + + private void Start() + { + rig = GetComponentInParent(); + data = GetComponentInParent(); + } + + //! 重要,这个代码会让角色站在地面上,不会陷下去 + // 和PlayerCollision的FixedUpdate代码配合 + private void FixedUpdate() + { + totalStepTime = 0f; + for (int i = 0; i < legs.Length; i++) + { + if (!legs[i].footDown) + { + totalStepTime += legs[i].stepTime; + } + } + for (int j = 0; j < legCastPositions.Length; j++) + { + RaycastHit2D[] array = Physics2D.RaycastAll(legCastPositions[j].transform.position + Vector3.up * 0.5f, Vector2.down, 1f * base.transform.root.localScale.x, mask); + for (int k = 0; k < array.Length; k++) + { + if ((bool)array[k].transform && array[k].transform.root != base.transform.root) + { + HitGround(legCastPositions[j], array[k]); + break; + } + } + } + } + + private void HitGround(Transform leg, RaycastHit2D hit) + { + if (!(data.sinceJump < 0.2f) && !(Vector3.Angle(Vector3.up, hit.normal) > 70f)) + { + data.TouchGround(hit.point, hit.normal, hit.rigidbody); + Vector3 vector = ((Vector3)hit.point - leg.transform.position) / base.transform.root.localScale.x; + if (data.input.direction.x != 0f) + { + vector.y += wobbleCurve.Evaluate(totalStepTime) * base.transform.root.localScale.x; + rig.AddForce(Vector3.up * forceCurve.Evaluate(totalStepTime) * rig.mass); + } + rig.AddForce(animationCurve.Evaluate(Mathf.Abs(vector.y)) * Vector3.up * rig.mass * force); + rig.AddForce(animationCurve.Evaluate(Mathf.Abs(vector.y)) * (0f - rig.velocity.y) * Vector2.up * rig.mass * drag); + } + } +} diff --git a/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.dll b/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.dll index 0b45c81..f6a0191 100644 Binary files a/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.dll and b/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.dll differ diff --git a/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.pdb b/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.pdb index fe42303..70deb69 100644 Binary files a/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.pdb and b/ROUNDS/bin/Debug/netstandard2.1/Assembly-CSharp.pdb differ diff --git a/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.dll b/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.dll index 0b45c81..f6a0191 100644 Binary files a/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.dll and b/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.dll differ diff --git a/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.pdb b/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.pdb index fe42303..70deb69 100644 Binary files a/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.pdb and b/ROUNDS/obj/Debug/netstandard2.1/Assembly-CSharp.pdb differ -- cgit v1.1-26-g67d0