blob: c62cd8392a009e4e01f7fd85339a1e32ec90868f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
using System;
using UnityEngine;
public class CameraFOVWithDistance : MonoBehaviour
{
public PlayerTracker tracker;
public Camera camera;
public float lerpSpeed = 0.15f;
private float _targetFOV;
private float _minDistance = 6.4f;
private float _maxDistance = 14.4f;
private float _minFOV = 35f;
private float _maxFOV = 73f;
private void Update()
{
var distancePercent = Mathf.InverseLerp(_minDistance, _maxDistance, Math.Clamp(tracker.Distance, _minDistance, _maxDistance));
_targetFOV = Mathf.Lerp(_minFOV, _maxFOV, distancePercent);
}
private void FixedUpdate()
{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, _targetFOV, lerpSpeed);
}
}
|