using UnityEngine; [RequireComponent(typeof(Camera))] public sealed class CameraFollowProbe : MonoBehaviour { [SerializeField] private Transform target; [SerializeField] private Vector3 worldOffset = new Vector3(0f, 3f, -6f); [SerializeField, Min(0.01f)] private float smoothTime = 0.25f; private Vector3 velocity; private void OnEnable() { velocity = Vector3.zero; } private void LateUpdate() { if (target == null || Time.deltaTime <= 0f) return; if (smoothTime <= 0f || float.IsNaN(smoothTime) || float.IsInfinity(smoothTime)) return; Vector3 desired = target.position + worldOffset; transform.position = Vector3.SmoothDamp(transform.position, desired, ref velocity, smoothTime); Vector3 direction = target.position - transform.position; if (direction.sqrMagnitude > 0.0001f && Vector3.Cross(direction, Vector3.up).sqrMagnitude > 0.0001f) transform.rotation = Quaternion.LookRotation(direction, Vector3.up); } }