Advertisement
Guest User

Untitled

a guest
May 21st, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. private static void PropAutoRotate(PropActor prop, Vector3 projectPosition)
  2.         {
  3.             Ray ray1 = new Ray(Vector3.zero, Quaternion.Euler(new Vector3(0, -0.01f, 0)) * (Vector3.zero + projectPosition) * 10);
  4.             Ray ray2 = new Ray(Vector3.zero, Quaternion.Euler(new Vector3(0, 0.01f, 0)) * (Vector3.zero + projectPosition) * 10);
  5.  
  6.             RaycastHit hit1;
  7.             RaycastHit hit2;
  8.  
  9.             Physics.Raycast(ray1, out hit1);
  10.             Physics.Raycast(ray2, out hit2);
  11.  
  12.             Vector3 plane = hit1.point - hit2.point;
  13.  
  14.             Vector3 myVector3 = -Vector3.Cross(plane.normalized, Vector3.up);
  15.  
  16.             float angle = Vector3.Angle(Vector3.left, myVector3);
  17.             float sign = Mathf.Sign(Vector3.Dot(Vector3.up, Vector3.Cross(Vector3.left, myVector3)));
  18.  
  19.             float signedAngle = angle * sign;
  20.  
  21.             float angle360 = (signedAngle + 180) % 360;
  22.             prop.transform.rotation = Quaternion.AngleAxis(angle360, Vector3.up);
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement