From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- CollisionChecker.cs | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 CollisionChecker.cs (limited to 'CollisionChecker.cs') diff --git a/CollisionChecker.cs b/CollisionChecker.cs new file mode 100644 index 0000000..83c247a --- /dev/null +++ b/CollisionChecker.cs @@ -0,0 +1,85 @@ +using UnityEngine; + +public class CollisionChecker : MonoBehaviour +{ + private Transform head; + + private Transform hip; + + private StandingDataHandler data; + + public bool active = true; + + public float sinceGrounded; + + private PickupHandler pickupHandler; + + private HasControl hasControl; + + public float allowedSteepnesAngle = 60f; + + private void Start() + { + pickupHandler = base.transform.root.GetComponent(); + hasControl = base.transform.root.GetComponent(); + data = GetComponentInParent(); + Head componentInChildren = base.transform.root.GetComponentInChildren(); + if ((bool)componentInChildren) + { + head = componentInChildren.transform; + } + Hip componentInChildren2 = base.transform.root.GetComponentInChildren(); + if ((bool)componentInChildren2) + { + hip = componentInChildren2.transform; + } + } + + private void Update() + { + sinceGrounded += Time.deltaTime; + } + + private void OnCollisionStay(Collision collision) + { + Collide(collision); + } + + private void OnCollisionEnter(Collision collision) + { + Collide(collision); + } + + private void Collide(Collision collision) + { + if (collision.transform.root == base.transform.root) + { + return; + } + if ((bool)collision.rigidbody) + { + Pickup component = collision.gameObject.GetComponent(); + if ((bool)component && !component.GetComponent().isHeld && hasControl.hasControl) + { + pickupHandler.PickUp(component); + } + if (collision.rigidbody.mass < 100f || collision.rigidbody.velocity.magnitude > 1f) + { + return; + } + } + if (active && Vector3.Angle(Vector3.up, collision.contacts[0].normal) < allowedSteepnesAngle) + { + if ((bool)data) + { + data.TouchGround(Mathf.Abs(hip.position.y - collision.contacts[0].point.y), collision.contacts[0].normal); + } + sinceGrounded = 0f; + } + } + + public void SwitchActive(bool setActive) + { + active = setActive; + } +} -- cgit v1.1-26-g67d0