Update PlayerAgent.cs

This commit is contained in:
Hazim Bin Ijaz 2025-09-26 02:56:05 +05:00
parent 36fd1709c1
commit ccb7f30912

View File

@ -84,10 +84,8 @@ namespace Projectiles
ProcessMovementInput(); ProcessMovementInput();
} }
// Keep pivot pitch synced to KCC look (we set it in LateUpdate on local) // REMOVED: Don't set camera pivot here - it conflicts with LateUpdate
var pitchYaw = KCC.GetLookRotation(true, true); // (x=pitch, y=yaw) // Store the look rotation for LateUpdate to use
_cameraPivot.localRotation = Quaternion.Euler(pitchYaw.x, 0f, 0f);
_lastFUNLookRotation = KCC.GetLookRotation(); _lastFUNLookRotation = KCC.GetLookRotation();
} }
@ -113,8 +111,8 @@ namespace Projectiles
} }
// 2) Apply current pitch to pivot for everyone (affects remote weapon aim too) // 2) Apply current pitch to pivot for everyone (affects remote weapon aim too)
var pitchOnly = KCC.GetLookRotation(true, false); var currentLook = KCC.GetLookRotation(true, true); // Get both pitch and yaw
_cameraPivot.localRotation = Quaternion.Euler(pitchOnly); _cameraPivot.localRotation = Quaternion.Euler(currentLook.x, 0f, 0f);
// 3) Position the actual camera (LOCAL ONLY) with shoulder offset + collision // 3) Position the actual camera (LOCAL ONLY) with shoulder offset + collision
if (HasInputAuthority) if (HasInputAuthority)
@ -125,7 +123,7 @@ namespace Projectiles
Vector3 pivotWorld = _cameraPivot.TransformPoint(_shoulderOffset); Vector3 pivotWorld = _cameraPivot.TransformPoint(_shoulderOffset);
// Camera wants to sit behind pivot along its backward vector // 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 desiredOffset = yawWorld * new Vector3(0f, 0f, -_cameraDistance);
Vector3 desiredPos = pivotWorld + desiredOffset; Vector3 desiredPos = pivotWorld + desiredOffset;
@ -148,11 +146,14 @@ namespace Projectiles
finalPos = pivotWorld + dir * dist; finalPos = pivotWorld + dir * dist;
cam.position = finalPos; 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) // Keep your optional handle aligned to the camera (muzzle/crosshair visuals)
_cameraHandle.position = cam.position; if (_cameraHandle != null)
_cameraHandle.rotation = cam.rotation; {
_cameraHandle.position = cam.position;
_cameraHandle.rotation = cam.rotation;
}
} }
} }
@ -197,9 +198,10 @@ namespace Projectiles
if (faceDir.sqrMagnitude > 0.0001f) if (faceDir.sqrMagnitude > 0.0001f)
{ {
Quaternion target = Quaternion.LookRotation(faceDir, Vector3.up); Quaternion target = Quaternion.LookRotation(faceDir, Vector3.up);
// Rotate the KCC transform smoothly (turnSpeed deg/sec) // FIXED: Use transform rotation instead of overriding look rotation
Quaternion newRot = Quaternion.RotateTowards(KCC.TransformRotation, target, _turnSpeed * Runner.DeltaTime); // This prevents interfering with camera pitch
KCC.SetLookRotation(newRot); Quaternion newRot = Quaternion.RotateTowards(transform.rotation, target, _turnSpeed * Runner.DeltaTime);
transform.rotation = newRot;
} }
// 5) Jump // 5) Jump
@ -210,4 +212,4 @@ namespace Projectiles
KCC.Move(_moveVelocity, jumpImpulse); KCC.Move(_moveVelocity, jumpImpulse);
} }
} }
} }