using UnityEngine;
using System.Collections;

public class ThirdPersonCamera : MonoBehaviour {
    [SerializeField] private GameObject _target;
    [SerializeField] private float _damping = 1;
    [SerializeField] private float _rotateSpeed = 1;
    [SerializeField] private float _angle = 40;

    private Vector3 _offset;
     
    
    void Start()
    {
        _offset = _target.transform.position - transform.position;
    }
    
    void LateUpdate()
    {
        float angleX = transform.eulerAngles.y + Input.GetAxis("Mouse X") * _rotateSpeed;
        _angle -= Input.GetAxis("Mouse Y") * _rotateSpeed;
        _angle = Mathf.Clamp(_angle, 10, 50);
        Quaternion rotation = Quaternion.Euler(_angle, angleX, 0);
        transform.position = _target.transform.position - (rotation * _offset);
        transform.LookAt(_target.transform);
    }

}
