Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraController : MonoBehaviour {
  6.  
  7. public bool lockCursor;
  8. public float mouseSensitvity = 10f;
  9. public Transform target;
  10. public float distanceFromTarget = 2f;
  11. public Vector2 pitchMinMax = new Vector2(-45, 85);
  12.  
  13. public float rotationSmoothTime = .12f;
  14. Vector3 rotationSmoothVelocity;
  15. Vector3 currentRotation;
  16.  
  17. float yaw;
  18. float pitch;
  19.  
  20. private void Start()
  21. {
  22. if (lockCursor)
  23. {
  24. Cursor.lockState = CursorLockMode.Locked;
  25. Cursor.visible = false;
  26. }
  27. }
  28.  
  29. private void LateUpdate()
  30. {
  31.  
  32.  
  33. yaw += Input.GetAxis("Mouse X") * mouseSensitvity;
  34. pitch -= Input.GetAxis("Mouse Y") * mouseSensitvity;
  35. pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
  36.  
  37. currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
  38. transform.eulerAngles = currentRotation;
  39. Vector3 e = transform.eulerAngles;
  40. e.x = 0;
  41.  
  42. if (!(PlayerController.instance.move == new Vector3(0f, 0f, 0f)))
  43. {
  44. target.eulerAngles = e;
  45.  
  46. }
  47. transform.position = target.position - transform.forward * distanceFromTarget;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement