Smooth 3C & simplify hallucination trigger
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using Unheimlich.Core;
|
||||
using Unheimlich.Features.Player.Data;
|
||||
using Unheimlich.Features.Dialogue;
|
||||
using InputManager = Unheimlich.Core.Input.InputManager;
|
||||
@@ -7,7 +8,7 @@ using InputManager = Unheimlich.Core.Input.InputManager;
|
||||
namespace Unheimlich.Features.Player
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles camera effects: aim assist and shake.
|
||||
/// Handles camera effects: aim assist, shake, and FOV kick on sprint.
|
||||
/// </summary>
|
||||
public class CameraEffects : MonoBehaviour
|
||||
{
|
||||
@@ -22,29 +23,62 @@ namespace Unheimlich.Features.Player
|
||||
private Vector3 _pendingAimAssistTarget;
|
||||
private bool _hasAimAssistTarget;
|
||||
|
||||
// FOV kick
|
||||
private float _baseFov = -1f;
|
||||
private float _currentFovOffset = 0f;
|
||||
|
||||
public bool IsAimLocked { get; private set; }
|
||||
public bool HasActiveLookInput { get; private set; }
|
||||
public bool IsUsingGamepad { get; private set; }
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
if (Settings != null)
|
||||
_shakeInterval = 1f / Settings.shakeFrequency;
|
||||
|
||||
if (PlayerController.Instance?.PlayerCamera != null)
|
||||
_baseFov = PlayerController.Instance.PlayerCamera.fieldOfView;
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
DetectInputDevice();
|
||||
UpdateFovKick();
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (_hasAimAssistTarget)
|
||||
{
|
||||
ApplyAimAssistInternal(_pendingAimAssistTarget);
|
||||
}
|
||||
}
|
||||
|
||||
// ── FOV Kick ─────────────────────────────────────────────────────────────
|
||||
|
||||
private void UpdateFovKick()
|
||||
{
|
||||
if (Settings == null || PlayerController.Instance?.PlayerCamera == null) return;
|
||||
|
||||
// Capture base FOV once (handles cases where FOV is changed externally before Start).
|
||||
if (_baseFov < 0f)
|
||||
_baseFov = PlayerController.Instance.PlayerCamera.fieldOfView;
|
||||
|
||||
float targetOffset = PlayerController.Instance.IsRunning ? Settings.fovKickAmount : 0f;
|
||||
_currentFovOffset = Mathf.Lerp(_currentFovOffset, targetOffset, Time.deltaTime * Settings.fovKickSpeed);
|
||||
|
||||
PlayerController.Instance.PlayerCamera.fieldOfView = _baseFov + _currentFovOffset;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the base FOV reference. Call this if the camera FOV is changed intentionally at runtime.
|
||||
/// </summary>
|
||||
public void ResetBaseFov()
|
||||
{
|
||||
if (PlayerController.Instance?.PlayerCamera != null)
|
||||
_baseFov = PlayerController.Instance.PlayerCamera.fieldOfView;
|
||||
}
|
||||
|
||||
// ── Input device detection ────────────────────────────────────────────────
|
||||
|
||||
private void DetectInputDevice()
|
||||
{
|
||||
Vector2 lookInput = InputManager.GetLookInput();
|
||||
@@ -56,11 +90,15 @@ namespace Unheimlich.Features.Player
|
||||
IsUsingGamepad = false;
|
||||
}
|
||||
|
||||
// ── Camera Shake ──────────────────────────────────────────────────────────
|
||||
|
||||
public void ShakeCamera(float amplitude, float smoothness = 0f)
|
||||
{
|
||||
if (PlayerController.Instance == null || PlayerController.Instance.CameraPivot == null || Settings == null)
|
||||
if (PlayerController.Instance == null || PlayerController.Instance.CameraPivot == null || Settings == null)
|
||||
return;
|
||||
|
||||
PlayerEvents.TriggerCameraShake(amplitude);
|
||||
|
||||
_shakeSmoothness = smoothness;
|
||||
_shakeTimer -= Time.deltaTime;
|
||||
|
||||
@@ -78,8 +116,8 @@ namespace Unheimlich.Features.Player
|
||||
if (_shakeSmoothness > 0f)
|
||||
{
|
||||
PlayerController.Instance.CameraPivot.position = Vector3.Lerp(
|
||||
PlayerController.Instance.CameraPivot.position,
|
||||
_shakeTarget,
|
||||
PlayerController.Instance.CameraPivot.position,
|
||||
_shakeTarget,
|
||||
Time.deltaTime * _shakeSmoothness);
|
||||
}
|
||||
else
|
||||
@@ -88,6 +126,8 @@ namespace Unheimlich.Features.Player
|
||||
}
|
||||
}
|
||||
|
||||
// ── Aim Assist ────────────────────────────────────────────────────────────
|
||||
|
||||
public void ApplyAimAssist(Vector3 targetCenter)
|
||||
{
|
||||
_pendingAimAssistTarget = targetCenter;
|
||||
@@ -96,9 +136,9 @@ namespace Unheimlich.Features.Player
|
||||
|
||||
private void ApplyAimAssistInternal(Vector3 targetCenter)
|
||||
{
|
||||
if (PlayerController.Instance == null || PlayerController.Instance.CameraTransform == null || Settings == null)
|
||||
if (PlayerController.Instance == null || PlayerController.Instance.CameraTransform == null || Settings == null)
|
||||
return;
|
||||
|
||||
|
||||
if (PlayerController.Instance.Movement == null)
|
||||
return;
|
||||
|
||||
@@ -113,17 +153,17 @@ namespace Unheimlich.Features.Player
|
||||
Vector3 targetDirection = directionToTarget;
|
||||
float targetYaw = Mathf.Atan2(targetDirection.x, targetDirection.z) * Mathf.Rad2Deg;
|
||||
float targetPitch = -Mathf.Asin(targetDirection.y) * Mathf.Rad2Deg;
|
||||
|
||||
|
||||
float currentYaw = PlayerController.Instance.Movement.Yaw;
|
||||
float currentPitch = PlayerController.Instance.Movement.Pitch;
|
||||
|
||||
|
||||
float newYaw = Mathf.LerpAngle(currentYaw, targetYaw, Settings.aimAssistStrength * Time.deltaTime);
|
||||
float newPitch = Mathf.Lerp(currentPitch, targetPitch, Settings.aimAssistStrength * Time.deltaTime);
|
||||
|
||||
|
||||
PlayerController.Instance.Movement.Yaw = newYaw;
|
||||
PlayerController.Instance.Movement.Pitch = newPitch;
|
||||
}
|
||||
|
||||
|
||||
_hasAimAssistTarget = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user