Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class CameraController : MonoBehaviour
- {
- public float SensitivityX;
- public float SensitivityY;
- public float MinXClamp;
- public float MaxXClamp;
- public Vector3 CameraOffset;
- public float CameraOffsetLength;
- public Transform Character;
- public LayerMask PlayerLayer;
- public float Smoothness;
- [HideInInspector]
- public Quaternion CameraDirection;
- float x;
- float y;
- private void Update()
- {
- x -= Input.GetAxisRaw("Mouse Y") * SensitivityX;
- y += Input.GetAxisRaw("Mouse X") * SensitivityY;
- x = Mathf.Clamp(x, MinXClamp, MaxXClamp);
- CameraDirection = Quaternion.Euler(x, y, 0);
- transform.rotation = CameraDirection;
- RaycastHit hit;
- if (Physics.Raycast(Character.position + CameraOffset, -transform.forward, out hit, CameraOffsetLength , PlayerLayer))
- {
- float c = hit.distance - CameraOffsetLength * 0.1f;
- transform.position = (Character.position + CameraOffset) + -transform.forward * c;
- }
- else
- transform.position = Character.position + CameraOffset + (-transform.forward * CameraOffsetLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement