refactoring

master
Jordan Orelli 5 years ago
parent 8d667d07cb
commit c1a179ae98

@ -44,17 +44,20 @@ public class MoveController : MonoBehaviour
rayOrigin += Vector3.up * (horizontalRaySpacing * i);
rayOrigin += Vector3.back * (horizontalRaySpacing * j);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.right * directionX, rayLength, collisionMask);
if (hits.Length > 0) {
float minHitDist = hits[0].distance;
foreach(RaycastHit hit in hits) {
if (hit.distance < minHitDist) {
minHitDist = hit.distance;
if (hits.Length == 0) {
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength, Color.green);
continue;
}
RaycastHit hit = hits[0];
for (int h = 1; h < hits.Length; h++) {
if (hits[h].distance < hit.distance) {
hit = hits[h];
}
velocity.x = (minHitDist - skinWidth) * directionX;
Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, minHitDist, velocity.y);
rayLength = minHitDist;
}
velocity.x = (hit.distance - skinWidth) * directionX;
Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y);
rayLength = hit.distance;
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength, Color.red);
if (directionX == -1) {
@ -62,9 +65,6 @@ public class MoveController : MonoBehaviour
} else {
collisions.right = true;
}
} else {
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength, Color.green);
}
}
}
}
@ -79,17 +79,20 @@ public class MoveController : MonoBehaviour
rayOrigin += Vector3.right * (verticalRaySpacing * i + velocity.x);
rayOrigin += Vector3.forward * (verticalRaySpacing * j + velocity.x);
RaycastHit[] hits = Physics.RaycastAll(rayOrigin, Vector3.up * directionY, rayLength, collisionMask);
if (hits.Length > 0) {
float minHitDist = hits[0].distance;
foreach(RaycastHit hit in hits) {
if (hit.distance < minHitDist) {
minHitDist = hit.distance;
if (hits.Length == 0) {
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.green);
continue;
}
RaycastHit hit = hits[0];
for (int h = 1; h < hits.Length; h++) {
if (hits[h].distance < hit.distance) {
hit = hits[h];
}
velocity.y = (minHitDist - skinWidth) * directionY;
Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, minHitDist, velocity.y);
rayLength = minHitDist;
}
velocity.y = (hit.distance - skinWidth) * directionY;
Debug.LogFormat("with RayLength {0} MinHitDist {1} setting velocity.y to {2}", rayLength, hit.distance, velocity.y);
rayLength = hit.distance;
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.red);
if (directionY == -1) {
@ -97,9 +100,6 @@ public class MoveController : MonoBehaviour
} else {
collisions.above = true;
}
} else {
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.green);
}
}
}
}

Loading…
Cancel
Save