修改角色控制旋转逻辑
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user