Advertisement
DevMerlin

Untitled

Jan 24th, 2021
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1.     private void orient()
  2.     {
  3.         Vector3 center = transform.position;
  4.         Vector3 backLeft = center;
  5.         Vector3 backRight = center;
  6.         Vector3 frontLeft = center;
  7.         Vector3 frontRight = center;
  8.  
  9.         backLeft.x = center.x - offsetForward;
  10.         backLeft.z = center.z - offsetSide;
  11.  
  12.         backRight.x = center.x + offsetForward;
  13.         backRight.z = center.z - offsetSide;
  14.  
  15.         frontLeft.x = center.x - offsetForward;
  16.         frontLeft.z = center.z + offsetSide;
  17.  
  18.         frontRight.x = center.x + offsetForward;
  19.         frontRight.z = center.z + offsetSide;
  20.  
  21.  
  22.         Physics.Raycast(backLeft + Vector3.up, Vector3.down, out lr, rayHeight, ~ignoreMask);
  23.         Physics.Raycast(backRight + Vector3.up, Vector3.down, out rr, rayHeight, ~ignoreMask);
  24.         Physics.Raycast(frontLeft + Vector3.up, Vector3.down, out lf, rayHeight, ~ignoreMask);
  25.         Physics.Raycast(frontRight + Vector3.up, Vector3.down, out rf, rayHeight, ~ignoreMask);
  26.  
  27.         Vector3 a = rr.point - lr.point;
  28.         Vector3 b = rf.point - rr.point;
  29.         Vector3 c = lf.point - rf.point;
  30.         Vector3 d = rr.point - lf.point;
  31.  
  32.         Vector3 crossBA = Vector3.Cross(b, a);
  33.         Vector3 crossCB = Vector3.Cross(c, b);
  34.         Vector3 crossDC = Vector3.Cross(d, c);
  35.         Vector3 crossAD = Vector3.Cross(a, d);
  36.  
  37.         orientation = (crossBA + crossCB + crossDC + crossAD);
  38.         transform.up += (transform.up - orientation.normalized);
  39.  
  40.         Debug.DrawLine(backLeft + Vector3.up, lr.point);
  41.         Debug.DrawLine(backRight + Vector3.up, rr.point);
  42.         Debug.DrawLine(frontLeft + Vector3.up, lf.point);
  43.         Debug.DrawLine(frontRight + Vector3.up, rf.point);
  44.     }
  45.  
  46.     private void distanceToGroundCheck()
  47.     {
  48.         Vector3 checkPoint = transform.position + Vector3.up;
  49.         checkPoint.x -= offsetForward;
  50.         Physics.Raycast(checkPoint, Vector3.down, out sr, rayHeight, ~ignoreMask);
  51.         Debug.DrawLine(checkPoint, sr.point);
  52.         groundYPoint = sr.point.y;
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement