修改角色控制旋转逻辑
This commit is contained in:
@@ -268,8 +268,8 @@ namespace NBF.Fishing2
|
|||||||
|
|
||||||
private void UpdateMovement()
|
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;
|
Vector3 movement = movementDirection * currentMoveState.moveSpeed * Time.deltaTime;
|
||||||
networkPosition += movement;
|
networkPosition += movement;
|
||||||
@@ -315,6 +315,7 @@ namespace NBF.Fishing2
|
|||||||
private Vector3 _rotationInput = Vector3.zero;
|
private Vector3 _rotationInput = Vector3.zero;
|
||||||
private float rotationSyncTimer;
|
private float rotationSyncTimer;
|
||||||
private Vector3 lastSyncedFacing;
|
private Vector3 lastSyncedFacing;
|
||||||
|
private bool isRotating = false;
|
||||||
|
|
||||||
[Tooltip("视角旋转敏感度")] public Vector2 sensitivity = new Vector2(0.015f, 0.015f);
|
[Tooltip("视角旋转敏感度")] public Vector2 sensitivity = new Vector2(0.015f, 0.015f);
|
||||||
|
|
||||||
@@ -327,17 +328,15 @@ namespace NBF.Fishing2
|
|||||||
if (lookInput.x != 0.0f)
|
if (lookInput.x != 0.0f)
|
||||||
{
|
{
|
||||||
_rotationInput.y += lookInput.x;
|
_rotationInput.y += lookInput.x;
|
||||||
|
isRotating = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 应用旋转到角色和相机
|
// 应用旋转到角色和相机
|
||||||
if (_rotationInput != Vector3.zero)
|
if (_rotationInput != Vector3.zero)
|
||||||
{
|
{
|
||||||
characterController.transform.rotation *= Quaternion.Euler(0, _rotationInput.y, 0);
|
characterController.transform.rotation *= Quaternion.Euler(0, _rotationInput.y, 0);
|
||||||
_rotationInput = Vector3.zero;
|
_rotationInput = Vector3.zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查朝向同步
|
// 检查朝向同步
|
||||||
@@ -348,15 +347,17 @@ namespace NBF.Fishing2
|
|||||||
{
|
{
|
||||||
float angleChange = Vector3.Angle(transform.forward, lastSyncedFacing);
|
float angleChange = Vector3.Angle(transform.forward, lastSyncedFacing);
|
||||||
|
|
||||||
if (angleChange >= minRotationChange)
|
// 修改:即使在旋转中也定期同步朝向,避免累积误差
|
||||||
|
if (angleChange >= minRotationChange || isRotating)
|
||||||
{
|
{
|
||||||
SendLookMessage();
|
SendLookMessage();
|
||||||
lastSyncedFacing = transform.forward;
|
lastSyncedFacing = transform.forward;
|
||||||
rotationSyncTimer = 0f;
|
rotationSyncTimer = 0f;
|
||||||
|
isRotating = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user