From 179c1982b802daf761d900c864f107e23758daec Mon Sep 17 00:00:00 2001 From: BobSong <605277374@qq.com> Date: Wed, 10 Sep 2025 22:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E6=97=8B=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unit/Unity/CharacterControllerComponent.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Fishing2/Unit/Unity/CharacterControllerComponent.cs b/Assets/Scripts/Fishing2/Unit/Unity/CharacterControllerComponent.cs index 1e97215df..976e92933 100644 --- a/Assets/Scripts/Fishing2/Unit/Unity/CharacterControllerComponent.cs +++ b/Assets/Scripts/Fishing2/Unit/Unity/CharacterControllerComponent.cs @@ -268,8 +268,8 @@ namespace NBF.Fishing2 private void UpdateMovement() { - var movementDirection = - currentMoveState.moveDirection.relativeTo(BaseCamera.Main.transform, characterController.transform.up); + // 修改:使用世界坐标方向而不是相对坐标方向 + Vector3 movementDirection = currentMoveState.moveDirection; Vector3 movement = movementDirection * currentMoveState.moveSpeed * Time.deltaTime; networkPosition += movement; @@ -315,6 +315,7 @@ namespace NBF.Fishing2 private Vector3 _rotationInput = Vector3.zero; private float rotationSyncTimer; private Vector3 lastSyncedFacing; + private bool isRotating = false; [Tooltip("视角旋转敏感度")] public Vector2 sensitivity = new Vector2(0.015f, 0.015f); @@ -327,17 +328,15 @@ namespace NBF.Fishing2 if (lookInput.x != 0.0f) { _rotationInput.y += lookInput.x; + isRotating = true; } - - // 应用旋转到角色和相机 if (_rotationInput != Vector3.zero) { characterController.transform.rotation *= Quaternion.Euler(0, _rotationInput.y, 0); _rotationInput = Vector3.zero; } - } // 检查朝向同步 @@ -348,15 +347,17 @@ namespace NBF.Fishing2 { float angleChange = Vector3.Angle(transform.forward, lastSyncedFacing); - if (angleChange >= minRotationChange) + // 修改:即使在旋转中也定期同步朝向,避免累积误差 + if (angleChange >= minRotationChange || isRotating) { SendLookMessage(); lastSyncedFacing = transform.forward; rotationSyncTimer = 0f; + isRotating = false; } } } #endregion } -} +} \ No newline at end of file