This commit is contained in:
Scove
2026-03-27 20:20:06 +07:00
parent df1377206a
commit ed67b8258d
4 changed files with 82 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
using UnityEngine;
using static OnlyScove.Scripts.CameraController;
using static OnlyScove.Scripts.CameraController;
namespace OnlyScove.Scripts
{
@@ -22,8 +22,8 @@ namespace OnlyScove.Scripts
private float _rotationY;
private float _lastInputTime;
public Quaternion CurrentRotation { get; private set; }
public Quaternion PlanarRotation => Quaternion.Euler(0f, _rotationY, 0f);
public Quaternion CurrentRotation { get; private set; } // Camera's actual rotation
public Quaternion PlanarRotation => Quaternion.Euler(0f, _rotationY, 0f); // Horizontal rotation (for player body in FPV)
public void Initialize(Transform cameraTransform)
{
@@ -33,10 +33,27 @@ namespace OnlyScove.Scripts
CurrentRotation = cameraTransform.rotation;
}
// New method to initialize rotation specifically for FPV
public void InitializeFPV(Transform fpvTargetTransform)
{
_rotationX = fpvTargetTransform.localEulerAngles.x; // Use local rotation for vertical angle in FPV
_rotationY = fpvTargetTransform.eulerAngles.y; // Use world rotation for horizontal angle
_lastInputTime = Time.time;
CurrentRotation = fpvTargetTransform.rotation; // Camera starts matching fpvTarget rotation
}
public void HandleRotation(InputReader inputReader, Transform followTarget, float rotationSmoothTime, CameraViewMode viewMode)
{
if (inputReader == null || viewMode == CameraViewMode.FirstPerson) return; // Only process input in TPV
if (inputReader == null) return;
// Debug for rotation
if (inputReader.LookInput.sqrMagnitude > 0.001f)
{
Debug.Log($"[CameraRotationHandler] LookInput: {inputReader.LookInput}, _rotationX: {_rotationX}, _rotationY: {_rotationY}, ViewMode: {viewMode}");
}
// Update _lastInputTime regardless of view mode if there's look input
if (inputReader.LookInput.magnitude > 0.01f)
{
_lastInputTime = Time.time;
@@ -50,17 +67,27 @@ namespace OnlyScove.Scripts
_rotationY += inputReader.LookInput.x * invertXVal * sensitivity * Time.deltaTime;
// Auto-Correction
if (useAutoRotation && Time.time - _lastInputTime > autoRotateDelay)
if (viewMode == CameraViewMode.ThirdPerson)
{
if (inputReader.MoveInput.magnitude > 0.1f)
// Auto-Correction for TPV
if (useAutoRotation && Time.time - _lastInputTime > autoRotateDelay)
{
float targetYaw = followTarget.eulerAngles.y;
_rotationY = Mathf.LerpAngle(_rotationY, targetYaw, autoRotateSpeed * Time.deltaTime);
if (inputReader.MoveInput.magnitude > 0.1f)
{
float targetYaw = followTarget.eulerAngles.y;
_rotationY = Mathf.LerpAngle(_rotationY, targetYaw, autoRotateSpeed * Time.deltaTime);
}
}
Quaternion targetRotation = Quaternion.Euler(_rotationX, _rotationY, 0f);
CurrentRotation = Quaternion.Slerp(CurrentRotation, targetRotation, rotationSmoothTime * Time.deltaTime);
}
else // FirstPerson
{
// In FPV, CurrentRotation *is* the camera's rotation (head rotation)
// The horizontal part of this (_rotationY) will also be used to rotate the player's body.
Quaternion targetRotation = Quaternion.Euler(_rotationX, _rotationY, 0f);
CurrentRotation = Quaternion.Slerp(CurrentRotation, targetRotation, rotationSmoothTime * Time.deltaTime);
}
Quaternion targetRotation = Quaternion.Euler(_rotationX, _rotationY, 0f);
CurrentRotation = Quaternion.Slerp(CurrentRotation, targetRotation, rotationSmoothTime * Time.deltaTime);
}
}
}