Skip to content

Commit 527f4d3

Browse files
committed
Merge branch 'develop' into feature/spot
2 parents fa6f411 + 18ecee0 commit 527f4d3

18 files changed

+683
-293
lines changed

Editor/CustomEditors/ZOSpotControllerEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace ZO.Editor {
1212

13-
[CustomEditor(typeof(ZOSpotController))]
13+
[CustomEditor(typeof(ZOSpotROSController))]
1414
public class ZOSpotControllerEditor : UnityEditor.Editor {
1515

1616
/// <summary>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
4+
namespace ZO {
5+
6+
public class ZOGroundDetector : MonoBehaviour {
7+
8+
public float _maxFloorAngle = 45;
9+
public bool _debug = false;
10+
11+
public float MaxFloorAngle {
12+
get => _maxFloorAngle;
13+
set => _maxFloorAngle = value;
14+
}
15+
16+
public CapsuleCollider CapsuleCollider {
17+
get {
18+
return GetComponent<CapsuleCollider>();
19+
}
20+
}
21+
22+
bool _isGrounded = false;
23+
public bool IsGrounded {
24+
get {
25+
return _isGrounded;
26+
}
27+
private set {
28+
_isGrounded = value;
29+
}
30+
}
31+
32+
Vector3 _groundNormal = -UnityEngine.Physics.gravity.normalized;
33+
public Vector3 GroundNormal {
34+
get => _groundNormal;
35+
private set => _groundNormal = value;
36+
}
37+
38+
Vector3 _groundPoint = Vector3.zero;
39+
public Vector3 GroundPoint {
40+
get => _groundPoint;
41+
private set => _groundPoint = value;
42+
}
43+
44+
// void OnCollisionEnter(Collision collision) {
45+
// IsGrounded = CheckIsGrounded(collision, CapsuleCollider, out _groundNormal);
46+
// }
47+
48+
void OnCollisionStay(Collision collision) {
49+
IsGrounded = CheckIsGrounded(collision);
50+
}
51+
52+
void OnCollisionExit(Collision collision) {
53+
IsGrounded = CheckIsGrounded(collision);
54+
}
55+
56+
bool CheckIsGrounded(Collision collision) {
57+
foreach (ContactPoint contactPoint in collision.contacts) {
58+
// if (contactPoint.thisCollider == capsuleCollider) {
59+
if (MaxFloorAngle > Vector3.Angle(contactPoint.normal, -UnityEngine.Physics.gravity.normalized)) {
60+
GroundNormal = contactPoint.normal;
61+
GroundPoint = contactPoint.point;
62+
63+
// Debug.DrawRay(contactPoint.point, contactPoint.normal * 100, Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f), 3f);
64+
65+
return true;
66+
}
67+
// }
68+
}
69+
70+
GroundNormal = -UnityEngine.Physics.gravity.normalized;
71+
72+
// foreach (var item in collision.contacts) {
73+
// Debug.DrawRay(item.point, item.normal * 100, Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f), 10f);
74+
// }
75+
76+
77+
return false;
78+
}
79+
80+
public void OnGUI() {
81+
if (_debug) {
82+
if (IsGrounded) {
83+
GUI.TextField(new Rect(10, 10, 500, 22), "On Ground");
84+
} else {
85+
GUI.TextField(new Rect(10, 10, 500, 22), "Off Ground");
86+
}
87+
88+
// Draw a different colored ray for every normal in the collision
89+
90+
}
91+
}
92+
93+
94+
}
95+
}

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotCharacterController.cs.meta renamed to Runtime/Scripts/Controllers/Robots/Spot/ZOGroundDetector.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotCharacterController.cs

Lines changed: 0 additions & 105 deletions
This file was deleted.

Runtime/Scripts/Controllers/Robots/Spot/ZOSpotController.cs

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)