From ccb7f3091217b10dc63d16e652b926b7786e6aa0 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Fri, 26 Sep 2025 02:56:05 +0500 Subject: [PATCH] Update PlayerAgent.cs --- Assets/Scripts/Player/PlayerAgent.cs | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Assets/Scripts/Player/PlayerAgent.cs b/Assets/Scripts/Player/PlayerAgent.cs index 26743f4..d1a75b2 100644 --- a/Assets/Scripts/Player/PlayerAgent.cs +++ b/Assets/Scripts/Player/PlayerAgent.cs @@ -84,10 +84,8 @@ namespace Projectiles ProcessMovementInput(); } - // Keep pivot pitch synced to KCC look (we set it in LateUpdate on local) - var pitchYaw = KCC.GetLookRotation(true, true); // (x=pitch, y=yaw) - _cameraPivot.localRotation = Quaternion.Euler(pitchYaw.x, 0f, 0f); - + // REMOVED: Don't set camera pivot here - it conflicts with LateUpdate + // Store the look rotation for LateUpdate to use _lastFUNLookRotation = KCC.GetLookRotation(); } @@ -113,8 +111,8 @@ namespace Projectiles } // 2) Apply current pitch to pivot for everyone (affects remote weapon aim too) - var pitchOnly = KCC.GetLookRotation(true, false); - _cameraPivot.localRotation = Quaternion.Euler(pitchOnly); + var currentLook = KCC.GetLookRotation(true, true); // Get both pitch and yaw + _cameraPivot.localRotation = Quaternion.Euler(currentLook.x, 0f, 0f); // 3) Position the actual camera (LOCAL ONLY) with shoulder offset + collision if (HasInputAuthority) @@ -125,7 +123,7 @@ namespace Projectiles Vector3 pivotWorld = _cameraPivot.TransformPoint(_shoulderOffset); // Camera wants to sit behind pivot along its backward vector - Quaternion yawWorld = Quaternion.Euler(0f, KCC.GetLookRotation(false, true).y, 0f); + Quaternion yawWorld = Quaternion.Euler(0f, currentLook.y, 0f); Vector3 desiredOffset = yawWorld * new Vector3(0f, 0f, -_cameraDistance); Vector3 desiredPos = pivotWorld + desiredOffset; @@ -148,11 +146,14 @@ namespace Projectiles finalPos = pivotWorld + dir * dist; cam.position = finalPos; - cam.rotation = Quaternion.Euler(pitchOnly.x, KCC.GetLookRotation(false, true).y, 0f); + cam.rotation = Quaternion.Euler(currentLook.x, currentLook.y, 0f); // Keep your optional handle aligned to the camera (muzzle/crosshair visuals) - _cameraHandle.position = cam.position; - _cameraHandle.rotation = cam.rotation; + if (_cameraHandle != null) + { + _cameraHandle.position = cam.position; + _cameraHandle.rotation = cam.rotation; + } } } @@ -197,9 +198,10 @@ namespace Projectiles if (faceDir.sqrMagnitude > 0.0001f) { Quaternion target = Quaternion.LookRotation(faceDir, Vector3.up); - // Rotate the KCC transform smoothly (turnSpeed deg/sec) - Quaternion newRot = Quaternion.RotateTowards(KCC.TransformRotation, target, _turnSpeed * Runner.DeltaTime); - KCC.SetLookRotation(newRot); + // FIXED: Use transform rotation instead of overriding look rotation + // This prevents interfering with camera pitch + Quaternion newRot = Quaternion.RotateTowards(transform.rotation, target, _turnSpeed * Runner.DeltaTime); + transform.rotation = newRot; } // 5) Jump @@ -210,4 +212,4 @@ namespace Projectiles KCC.Move(_moveVelocity, jumpImpulse); } } -} +} \ No newline at end of file