Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void orient()
- {
- Vector3 center = transform.position;
- Vector3 backLeft = center;
- Vector3 backRight = center;
- Vector3 frontLeft = center;
- Vector3 frontRight = center;
- backLeft.x = center.x - offsetForward;
- backLeft.z = center.z - offsetSide;
- backRight.x = center.x + offsetForward;
- backRight.z = center.z - offsetSide;
- frontLeft.x = center.x - offsetForward;
- frontLeft.z = center.z + offsetSide;
- frontRight.x = center.x + offsetForward;
- frontRight.z = center.z + offsetSide;
- Physics.Raycast(backLeft + Vector3.up, Vector3.down, out lr, rayHeight, ~ignoreMask);
- Physics.Raycast(backRight + Vector3.up, Vector3.down, out rr, rayHeight, ~ignoreMask);
- Physics.Raycast(frontLeft + Vector3.up, Vector3.down, out lf, rayHeight, ~ignoreMask);
- Physics.Raycast(frontRight + Vector3.up, Vector3.down, out rf, rayHeight, ~ignoreMask);
- Vector3 a = rr.point - lr.point;
- Vector3 b = rf.point - rr.point;
- Vector3 c = lf.point - rf.point;
- Vector3 d = rr.point - lf.point;
- Vector3 crossBA = Vector3.Cross(b, a);
- Vector3 crossCB = Vector3.Cross(c, b);
- Vector3 crossDC = Vector3.Cross(d, c);
- Vector3 crossAD = Vector3.Cross(a, d);
- orientation = (crossBA + crossCB + crossDC + crossAD);
- transform.up += (transform.up - orientation.normalized);
- Debug.DrawLine(backLeft + Vector3.up, lr.point);
- Debug.DrawLine(backRight + Vector3.up, rr.point);
- Debug.DrawLine(frontLeft + Vector3.up, lf.point);
- Debug.DrawLine(frontRight + Vector3.up, rf.point);
- }
- private void distanceToGroundCheck()
- {
- Vector3 checkPoint = transform.position + Vector3.up;
- checkPoint.x -= offsetForward;
- Physics.Raycast(checkPoint, Vector3.down, out sr, rayHeight, ~ignoreMask);
- Debug.DrawLine(checkPoint, sr.point);
- groundYPoint = sr.point.y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement