Update PlayerAgent.cs
This commit is contained in:
parent
36fd1709c1
commit
ccb7f30912
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user