|
|
@ -44,17 +44,20 @@ public class MoveController : MonoBehaviour
|
|
|
|
rayOrigin += Vector3.up * (horizontalRaySpacing * i);
|
|
|
|
rayOrigin += Vector3.up * (horizontalRaySpacing * i);
|
|
|
|
rayOrigin += Vector3.back * (horizontalRaySpacing * j);
|
|
|
|
rayOrigin += Vector3.back * (horizontalRaySpacing * 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, Color.green);
|
|
|
|
float minHitDist = hits[0].distance;
|
|
|
|
continue;
|
|
|
|
foreach(RaycastHit hit in hits) {
|
|
|
|
|
|
|
|
if (hit.distance < minHitDist) {
|
|
|
|
|
|
|
|
minHitDist = hit.distance;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
Debug.DrawRay(rayOrigin, Vector3.right * directionX * rayLength, Color.red);
|
|
|
|
|
|
|
|
|
|
|
|
if (directionX == -1) {
|
|
|
|
if (directionX == -1) {
|
|
|
@ -62,9 +65,6 @@ public class MoveController : MonoBehaviour
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
collisions.right = true;
|
|
|
|
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.right * (verticalRaySpacing * i + velocity.x);
|
|
|
|
rayOrigin += Vector3.forward * (verticalRaySpacing * j + velocity.x);
|
|
|
|
rayOrigin += Vector3.forward * (verticalRaySpacing * j + velocity.x);
|
|
|
|
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, Color.green);
|
|
|
|
float minHitDist = hits[0].distance;
|
|
|
|
continue;
|
|
|
|
foreach(RaycastHit hit in hits) {
|
|
|
|
|
|
|
|
if (hit.distance < minHitDist) {
|
|
|
|
|
|
|
|
minHitDist = hit.distance;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.red);
|
|
|
|
|
|
|
|
|
|
|
|
if (directionY == -1) {
|
|
|
|
if (directionY == -1) {
|
|
|
@ -97,9 +100,6 @@ public class MoveController : MonoBehaviour
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
collisions.above = true;
|
|
|
|
collisions.above = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Debug.DrawRay(rayOrigin, Vector3.up * directionY * rayLength, Color.green);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|