Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraController : MonoBehaviour {
- public bool lockCursor;
- public float mouseSensitvity = 10f;
- public Transform target;
- public float distanceFromTarget = 2f;
- public Vector2 pitchMinMax = new Vector2(-45, 85);
- public float rotationSmoothTime = .12f;
- Vector3 rotationSmoothVelocity;
- Vector3 currentRotation;
- float yaw;
- float pitch;
- private void Start()
- {
- if (lockCursor)
- {
- Cursor.lockState = CursorLockMode.Locked;
- Cursor.visible = false;
- }
- }
- private void LateUpdate()
- {
- yaw += Input.GetAxis("Mouse X") * mouseSensitvity;
- pitch -= Input.GetAxis("Mouse Y") * mouseSensitvity;
- pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
- currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
- transform.eulerAngles = currentRotation;
- Vector3 e = transform.eulerAngles;
- e.x = 0;
- if (!(PlayerController.instance.move == new Vector3(0f, 0f, 0f)))
- {
- target.eulerAngles = e;
- }
- transform.position = target.position - transform.forward * distanceFromTarget;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement