aboutsummaryrefslogtreecommitdiff
path: root/JamTools/Assets/JamTools/Scripts
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-01-27 20:14:23 +0800
committerchai <chaifix@163.com>2022-01-27 20:14:23 +0800
commit48ab4a903783ce6ecb102d2b9e1278716728bf82 (patch)
tree9a709729380a8385558fa70035c7a8ed7f570e70 /JamTools/Assets/JamTools/Scripts
parenta458d265d628e11ccdb747d616f5032af2cd54bd (diff)
*misc
Diffstat (limited to 'JamTools/Assets/JamTools/Scripts')
-rw-r--r--JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/FPSCharacterController.cs4
-rw-r--r--JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/PlayerBody.cs14
-rw-r--r--JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/WallChecker.cs40
-rw-r--r--JamTools/Assets/JamTools/Scripts/TestCollision.cs51
-rw-r--r--JamTools/Assets/JamTools/Scripts/TestCollision.cs.meta11
-rw-r--r--JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs59
-rw-r--r--JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs.meta11
7 files changed, 157 insertions, 33 deletions
diff --git a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/FPSCharacterController.cs b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/FPSCharacterController.cs
index c902a9d..c7a5560 100644
--- a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/FPSCharacterController.cs
+++ b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/FPSCharacterController.cs
@@ -261,8 +261,6 @@ namespace JamTools
if(Input.GetButtonDown("Jump"))
{
- Debug.Log(m_WallChecker.normal);
- m_Rigidbody.AddForce(m_WallChecker.normal * 100);
}
}
@@ -274,8 +272,6 @@ namespace JamTools
if (!m_WallChecker.IsOnWall)
return;
-
-
}
void PullTrick()
diff --git a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/PlayerBody.cs b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/PlayerBody.cs
index 074b6f0..709b756 100644
--- a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/PlayerBody.cs
+++ b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/PlayerBody.cs
@@ -4,6 +4,20 @@ using UnityEngine;
public class PlayerBody : MonoBehaviour
{
+ private CapsuleCollider m_CapsuleCollider;
+
+ public CapsuleCollider capsuleCollider
+ {
+ get
+ {
+ return m_CapsuleCollider;
+ }
+ }
+
+ private void Awake()
+ {
+ m_CapsuleCollider = GetComponent<CapsuleCollider>();
+ }
private void OnCollisionEnter(Collision collision)
{
diff --git a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/WallChecker.cs b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/WallChecker.cs
index 797b0b4..946c326 100644
--- a/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/WallChecker.cs
+++ b/JamTools/Assets/JamTools/Scripts/Character/FPSCharacterController/WallChecker.cs
@@ -14,51 +14,33 @@ public class WallChecker : MonoBehaviour
}
}
- private Vector3 m_Normal;
- public Vector3 normal
+ private List<Collider> m_Colliders = new List<Collider>();
+
+ private void Update()
{
- get
+ if (m_IsOnWall && m_Colliders.Count == 0)
{
- return m_Normal;
+ m_IsOnWall = false;
}
}
- private void OnCollisionEnter(Collision collision)
- {
- Debug.Log("OnCollisionEnter");
-
- m_IsOnWall = true;
- m_Normal = collision.contacts[0].normal;
- }
-
- private void OnCollisionStay(Collision collision)
- {
- m_IsOnWall = true;
-
- }
-
- private void OnCollisionExit(Collision collision)
- {
- m_IsOnWall = false;
-
- }
-
private void OnTriggerEnter(Collider other)
{
- Debug.Log("OnCollisionEnter");
-
m_IsOnWall = true;
+
+ m_Colliders.Add(other);
}
private void OnTriggerStay(Collider other)
{
- m_IsOnWall = true;
-
}
private void OnTriggerExit(Collider other)
{
- m_IsOnWall = false;
+ if(m_Colliders.Contains(other))
+ {
+ m_Colliders.Remove(other);
+ }
}
}
diff --git a/JamTools/Assets/JamTools/Scripts/TestCollision.cs b/JamTools/Assets/JamTools/Scripts/TestCollision.cs
new file mode 100644
index 0000000..87b018f
--- /dev/null
+++ b/JamTools/Assets/JamTools/Scripts/TestCollision.cs
@@ -0,0 +1,51 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TestCollision : MonoBehaviour
+{
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+
+ private void OnCollisionEnter(Collision collision)
+ {
+ Debug.Log("OnCollisionEnter");
+
+ }
+
+ private void OnCollisionStay(Collision collision)
+ {
+
+ }
+
+ private void OnCollisionExit(Collision collision)
+ {
+
+ }
+
+
+ private void OnTriggerEnter(Collider other)
+ {
+ Debug.Log("OnTriggerEnter");
+
+ }
+
+ private void OnTriggerStay(Collider other)
+ {
+
+ }
+
+ private void OnTriggerExit(Collider other)
+ {
+ }
+
+}
diff --git a/JamTools/Assets/JamTools/Scripts/TestCollision.cs.meta b/JamTools/Assets/JamTools/Scripts/TestCollision.cs.meta
new file mode 100644
index 0000000..4d5ff9b
--- /dev/null
+++ b/JamTools/Assets/JamTools/Scripts/TestCollision.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 08a344d0f26d38142afbf1868e8e57b6
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs b/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs
new file mode 100644
index 0000000..3efe155
--- /dev/null
+++ b/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace JamTools
+{
+
+ public static class ColliderUtility
+ {
+ private static readonly List<Vector3> s_Vertices = new List<Vector3>();
+
+ private static readonly List<int> s_Triangles = new List<int>();
+
+ private static Plane GetWorldTriangle(Transform collider, int index)
+ {
+ Vector3 position = ColliderUtility.s_Vertices[ColliderUtility.s_Triangles[3 * index]];
+ Vector3 position2 = ColliderUtility.s_Vertices[ColliderUtility.s_Triangles[3 * index + 1]];
+ Vector3 position3 = ColliderUtility.s_Vertices[ColliderUtility.s_Triangles[3 * index + 2]];
+ return new Plane(collider.TransformPoint(position), collider.TransformPoint(position2), collider.TransformPoint(position3));
+ }
+
+ public static Vector3 FindClosestPoint(Collider collider, Vector3 position)
+ {
+ return ColliderUtility.FindClosestPoint(collider, position, false);
+ }
+
+ public static Vector3 FindClosestPoint(Collider collider, Vector3 position, bool ignoreVerticalTriangles)
+ {
+ MeshCollider meshCollider;
+ if ((meshCollider = (collider as MeshCollider)) != null && !meshCollider.convex)
+ {
+ Mesh sharedMesh = meshCollider.sharedMesh;
+ sharedMesh.GetVertices(ColliderUtility.s_Vertices);
+ Plane plane = default(Plane);
+ float num = float.PositiveInfinity;
+ for (int i = 0; i < sharedMesh.subMeshCount; i++)
+ {
+ sharedMesh.GetTriangles(ColliderUtility.s_Triangles, i);
+ int j = 0;
+ int num2 = ColliderUtility.s_Triangles.Count / 3;
+ while (j < num2)
+ {
+ Plane worldTriangle = ColliderUtility.GetWorldTriangle(meshCollider.transform, j);
+ float num3 = Mathf.Abs(worldTriangle.GetDistanceToPoint(position));
+ if ((!ignoreVerticalTriangles || (!(worldTriangle.normal == Vector3.up) && !(worldTriangle.normal == Vector3.down))) && ((i == 0 && j == 0) || num3 < num))
+ {
+ plane = worldTriangle;
+ num = num3;
+ }
+ j++;
+ }
+ }
+ return plane.ClosestPointOnPlane(position);
+ }
+ return collider.ClosestPoint(position);
+ }
+ }
+
+}
diff --git a/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs.meta b/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs.meta
new file mode 100644
index 0000000..4d828ca
--- /dev/null
+++ b/JamTools/Assets/JamTools/Scripts/Utils/ColliderUtility.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 17d16ee713041694bb7486e050909dd8
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: