Files
BABA_YAGA/Assets/Scripts/Camera Controller/CameraDynamicFOV.cs

46 lines
1.7 KiB
C#
Raw Normal View History

2026-03-27 12:08:16 +07:00
using UnityEngine;
2026-03-27 12:27:50 +07:00
using static OnlyScove.Scripts.CameraController; // Need to add this to access CameraController.CameraViewMode
2026-03-27 12:08:16 +07:00
namespace OnlyScove.Scripts
{
[System.Serializable]
public class CameraDynamicFOV
{
[Header("Dynamic FOV")]
[SerializeField] private bool useDynamicFOV = true;
2026-03-27 12:27:50 +07:00
[SerializeField] private float tpvSprintFOV = 70f; // Renamed from sprintFOV for clarity
2026-04-02 08:59:51 +07:00
[SerializeField] private float fpvSprintFOV = 95f; // Target FOV for sprinting in FPV
2026-03-27 12:08:16 +07:00
[SerializeField] private float fovSmoothTime = 5f;
2026-03-27 12:27:50 +07:00
private float _currentTpvBaseFOV; // Stored from CameraController
private float _currentFpvFOV; // Stored from CameraController
public float CurrentTpvBaseFOV => _currentTpvBaseFOV; // Expose for CameraController transitions
public void Initialize(float tpvBaseFOV, float fpvFOV)
{
_currentTpvBaseFOV = tpvBaseFOV;
_currentFpvFOV = fpvFOV;
}
public void HandleDynamicFOV(Camera cam, InputReader inputReader, CameraViewMode viewMode)
2026-03-27 12:08:16 +07:00
{
if (!useDynamicFOV || cam == null || inputReader == null) return;
2026-04-02 08:59:51 +07:00
bool isSprinting = inputReader.MoveInput.magnitude > 0.1f && inputReader.IsSprintHeld;
float targetFOV;
2026-03-27 12:08:16 +07:00
2026-04-02 08:59:51 +07:00
if (viewMode == CameraViewMode.ThirdPerson)
2026-03-27 12:08:16 +07:00
{
2026-04-02 08:59:51 +07:00
targetFOV = isSprinting ? tpvSprintFOV : _currentTpvBaseFOV;
}
else // FirstPerson
{
targetFOV = isSprinting ? fpvSprintFOV : _currentFpvFOV;
2026-03-27 12:08:16 +07:00
}
cam.fieldOfView = Mathf.Lerp(cam.fieldOfView, targetFOV, fovSmoothTime * Time.deltaTime);
}
}
}