fix ray debug display

master
Jordan Orelli 5 years ago
parent cc002f28a1
commit 243f054d93

@ -527,6 +527,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 6891912346901077427, guid: cd445451907d7274daea79c67e13a202,
type: 3}
propertyPath: forwardRayCount
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: cd445451907d7274daea79c67e13a202, type: 3} m_SourcePrefab: {fileID: 100100000, guid: cd445451907d7274daea79c67e13a202, type: 3}
--- !u!1001 &8206000050524585146 --- !u!1001 &8206000050524585146

@ -9,6 +9,7 @@ public class MoveController : MonoBehaviour
public const float skinWidth = 0.015f; public const float skinWidth = 0.015f;
public int horizontalRayCount = 4; public int horizontalRayCount = 4;
public int verticalRayCount = 4; public int verticalRayCount = 4;
public int forwardRayCount = 4;
public CollisionInfo collisions; public CollisionInfo collisions;
public float maxClimbAngle = 80f; public float maxClimbAngle = 80f;
@ -16,6 +17,7 @@ public class MoveController : MonoBehaviour
private RaycastOrigins raycastOrigins; private RaycastOrigins raycastOrigins;
private float horizontalRaySpacing; private float horizontalRaySpacing;
private float verticalRaySpacing; private float verticalRaySpacing;
private float forwardRaySpacing;
void Start() { void Start() {
collider = GetComponent<BoxCollider>(); collider = GetComponent<BoxCollider>();
@ -41,14 +43,14 @@ public class MoveController : MonoBehaviour
float rayLength = Mathf.Abs(velocity.x) + skinWidth; float rayLength = Mathf.Abs(velocity.x) + skinWidth;
for (int i = 0; i < horizontalRayCount; i++) { for (int i = 0; i < horizontalRayCount; i++) {
for (int j = 0; j < horizontalRayCount; j++) { for (int j = 0; j < forwardRayCount; j++) {
Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomFrontLeft : raycastOrigins.bottomFrontRight; Vector3 rayOrigin = (directionX == -1) ? raycastOrigins.bottomFrontLeft : raycastOrigins.bottomFrontRight;
rayOrigin += Vector3.up * (horizontalRaySpacing * i); rayOrigin += Vector3.up * (horizontalRaySpacing * i);
rayOrigin += Vector3.back * (horizontalRaySpacing * j); rayOrigin += Vector3.forward * (forwardRaySpacing * j);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask); RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask);
if (hits.Length == 0) { if (hits.Length == 0) {
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength * 10, Color.magenta); Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.magenta);
continue; continue;
} }
@ -67,7 +69,7 @@ public class MoveController : MonoBehaviour
velocity.x = (hit.distance - skinWidth) * directionX; velocity.x = (hit.distance - skinWidth) * directionX;
// Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y); // Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y);
rayLength = hit.distance; rayLength = hit.distance;
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength, Color.red); Debug.DrawRay(rayOrigin + velocity, Vector3.right * directionX * rayLength, Color.red);
if (directionX == -1) { if (directionX == -1) {
collisions.left = true; collisions.left = true;
@ -83,13 +85,13 @@ public class MoveController : MonoBehaviour
float rayLength = Mathf.Abs(velocity.y) + skinWidth; float rayLength = Mathf.Abs(velocity.y) + skinWidth;
for (int i = 0; i < verticalRayCount; i++) { for (int i = 0; i < verticalRayCount; i++) {
for (int j = 0; j < verticalRayCount; j++) { for (int j = 0; j < forwardRayCount; j++) {
Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomFrontLeft : raycastOrigins.topFrontLeft; Vector3 rayOrigin = (directionY == -1) ? raycastOrigins.bottomFrontLeft : raycastOrigins.topFrontLeft;
rayOrigin += Vector3.right * (verticalRaySpacing * i + velocity.x); rayOrigin += Vector3.right * (verticalRaySpacing * i);
rayOrigin += Vector3.forward * (verticalRaySpacing * j + velocity.x); rayOrigin += Vector3.forward * (forwardRaySpacing * j);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, collisionMask); RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, collisionMask);
if (hits.Length == 0) { if (hits.Length == 0) {
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength * 10, Color.green); Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength * 10, Color.green);
continue; continue;
} }
RaycastHit hit = hits[0]; RaycastHit hit = hits[0];
@ -102,7 +104,7 @@ public class MoveController : MonoBehaviour
velocity.y = (hit.distance - skinWidth) * directionY; velocity.y = (hit.distance - skinWidth) * directionY;
// Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y); // Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y);
rayLength = hit.distance; rayLength = hit.distance;
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.red); Debug.DrawRay(rayOrigin + velocity, Vector3.up * directionY * rayLength, Color.red);
if (directionY == -1) { if (directionY == -1) {
collisions.below = true; collisions.below = true;
@ -134,9 +136,11 @@ public class MoveController : MonoBehaviour
if (horizontalRayCount < 2) { horizontalRayCount = 2; } if (horizontalRayCount < 2) { horizontalRayCount = 2; }
if (verticalRayCount < 2) { verticalRayCount = 2; } if (verticalRayCount < 2) { verticalRayCount = 2; }
if (forwardRayCount < 2) { forwardRayCount = 2; }
horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1); horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
verticalRaySpacing = bounds.size.x / (verticalRayCount - 1); verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
forwardRaySpacing = bounds.size.z / (forwardRayCount - 1);
} }
public bool Grounded() { return collisions.below; } public bool Grounded() { return collisions.below; }

Loading…
Cancel
Save