summaryrefslogtreecommitdiff
path: root/CollisionChecker.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /CollisionChecker.cs
+init
Diffstat (limited to 'CollisionChecker.cs')
-rw-r--r--CollisionChecker.cs85
1 files changed, 85 insertions, 0 deletions
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<PickupHandler>();
+ hasControl = base.transform.root.GetComponent<HasControl>();
+ data = GetComponentInParent<StandingDataHandler>();
+ Head componentInChildren = base.transform.root.GetComponentInChildren<Head>();
+ if ((bool)componentInChildren)
+ {
+ head = componentInChildren.transform;
+ }
+ Hip componentInChildren2 = base.transform.root.GetComponentInChildren<Hip>();
+ 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<Pickup>();
+ if ((bool)component && !component.GetComponent<HoldableObject>().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;
+ }
+}