Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. void Start()
  2. {
  3.  
  4. Vector3 angles = transform.eulerAngles;
  5. rotationYAxis = angles.y;
  6. rotationXAxis = angles.x;
  7.  
  8. // Make the rigid body not change rotation
  9. if (GetComponent<Rigidbody>())
  10. {
  11. GetComponent<Rigidbody>().freezeRotation = true;
  12. }
  13. }
  14.  
  15. void LateUpdate()
  16. {
  17. if (target)
  18. {
  19. if (ControlFreak2.CF2Input.GetMouseButton (0)) {
  20. velocityX += xSpeed * ControlFreak2.CF2Input.GetAxis ("Mouse X") * 0.02f;
  21. velocityY += ySpeed * ControlFreak2.CF2Input.GetAxis ("Mouse Y") * 0.02f;
  22.  
  23. }else{
  24.  
  25. velocityX += xSpeed * Input.GetAxis ("Horizontal2") * 0.02f;
  26. velocityY += ySpeed * Input.GetAxis ("Vertical2") * 0.02f;
  27.  
  28. }
  29.  
  30. rotationYAxis += velocityX;
  31. rotationXAxis -= velocityY;
  32.  
  33. rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
  34.  
  35. Quaternion fromRotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, 0);
  36. Quaternion toRotation = Quaternion.Euler(rotationXAxis, rotationYAxis, 0);
  37. Quaternion rotation = toRotation;
  38.  
  39. distance = Mathf.Clamp(distance - ControlFreak2.CF2Input.GetAxis("Mouse ScrollWheel")*Seconds, distanceMin, distanceMax);
  40.  
  41.  
  42. Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
  43. Vector3 position = rotation * negDistance + target.position;
  44.  
  45. transform.rotation = rotation;
  46. transform.position = position;
  47.  
  48. velocityX = Mathf.Lerp(velocityX, 0, Time.unscaledDeltaTime * smoothTime);
  49. velocityY = Mathf.Lerp(velocityY, 0, Time.unscaledDeltaTime * smoothTime);
  50. }
  51.  
  52. }
  53.  
  54. public static float ClampAngle(float angle, float min, float max)
  55. {
  56. if (angle < -360F)
  57. angle += 360F;
  58. if (angle > 360F)
  59. angle -= 360F;
  60. return Mathf.Clamp(angle, min, max);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement