AviatorUnlimited/Assets/Scripts/CameraFollower.cs
2023-07-15 13:17:08 +05:30

33 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public Vector3 smoothness = Vector3.one;
public Vector3 offset;
public float lookAtAngle = 10;
public float fovBoost = 10;
public Transform target;
float defFov;
void Start(){
if(target == null) {target= PlayerController.instance.transform;}
offset = transform.position - target.position;
defFov = Camera.main.fieldOfView;
}
// Update is called once per frame
void FixedUpdate()
{
Follow();
}
void Follow(){
// transform.position = Vector3.Lerp(transform.position, target.position + offset, smoothness);
transform.position = new Vector3(Mathf.Lerp(transform.position.x, target.position.x + offset.x, smoothness.x), Mathf.Lerp(transform.position.y,target.position.y+ offset.y, smoothness.y), Mathf.Lerp(transform.position.z,target.position.z+ offset.z, smoothness.z));
transform.localEulerAngles = new Vector3(0, (transform.position.x - target.position.x) * lookAtAngle ,0);
Camera.main.fieldOfView = defFov + (Mathf.Abs((transform.position.x - target.position.x)) * fovBoost);
}
}