应该解决了问题,问题来源:AI 在我不知情的情况下引入了刚体速度,导致客户端与服务端的状态一直对不上
This commit is contained in:
parent
1e90de11ce
commit
e60ad420dc
|
|
@ -492,7 +492,7 @@ MonoBehaviour:
|
||||||
_speed: 2
|
_speed: 2
|
||||||
_rigid: {fileID: -1362768914916555191}
|
_rigid: {fileID: -1362768914916555191}
|
||||||
_inputComponent: {fileID: 8938569698484985372}
|
_inputComponent: {fileID: 8938569698484985372}
|
||||||
_applyServerCorrection: 0
|
_applyServerCorrection: 1
|
||||||
_lerpRate: 0.1
|
_lerpRate: 0.1
|
||||||
--- !u!114 &8938569698484985372
|
--- !u!114 &8938569698484985372
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|
@ -508,7 +508,6 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_playerId: 1234
|
_playerId: 1234
|
||||||
_sendInterval: 0.05
|
_sendInterval: 0.05
|
||||||
_useNetwork: 1
|
|
||||||
--- !u!54 &-1362768914916555191
|
--- !u!54 &-1362768914916555191
|
||||||
Rigidbody:
|
Rigidbody:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,17 @@ public class MovementComponent : MonoBehaviour
|
||||||
_simulationAccumulator += Time.fixedDeltaTime;
|
_simulationAccumulator += Time.fixedDeltaTime;
|
||||||
while (_simulationAccumulator >= kServerSimulationStepSeconds)
|
while (_simulationAccumulator >= kServerSimulationStepSeconds)
|
||||||
{
|
{
|
||||||
|
var pendingCount = _predictionBuffer.PendingInputs.Count;
|
||||||
|
if (pendingCount == 0)
|
||||||
|
{
|
||||||
|
// 没有待处理的输入,清零累积时间,跳出循环
|
||||||
|
_simulationAccumulator = 0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.Log(
|
||||||
|
$"[SimulateLoop] frame={Time.frameCount} accum={_simulationAccumulator:F4} pendingCount={pendingCount}");
|
||||||
|
|
||||||
// 使用最近发送的 MoveInput(来自 predictionBuffer)而非实时输入,
|
// 使用最近发送的 MoveInput(来自 predictionBuffer)而非实时输入,
|
||||||
// 确保客户端与服务端的输入时序一致
|
// 确保客户端与服务端的输入时序一致
|
||||||
Simulate(GetLatestPredictedInput());
|
Simulate(GetLatestPredictedInput());
|
||||||
|
|
@ -209,8 +220,12 @@ public class MovementComponent : MonoBehaviour
|
||||||
|
|
||||||
private void Simulate(Vector3 input)
|
private void Simulate(Vector3 input)
|
||||||
{
|
{
|
||||||
|
Debug.Log(
|
||||||
|
$"[Simulate] frame={Time.frameCount} input=({input.x:F2},{input.z:F2}) accum={_simulationAccumulator:F4}");
|
||||||
ApplyTankMovement(-input.x, input.z, kServerSimulationStepSeconds);
|
ApplyTankMovement(-input.x, input.z, kServerSimulationStepSeconds);
|
||||||
|
|
||||||
|
//ApplyTankMovement(-input.x, input.z, kServerSimulationStepSeconds);
|
||||||
|
|
||||||
// 每次 Simulate 后累加模拟时间(用于 Reconcile 时的重放)
|
// 每次 Simulate 后累加模拟时间(用于 Reconcile 时的重放)
|
||||||
_predictionBuffer.AccumulateLatest(kServerSimulationStepSeconds);
|
_predictionBuffer.AccumulateLatest(kServerSimulationStepSeconds);
|
||||||
|
|
||||||
|
|
@ -344,8 +359,10 @@ public class MovementComponent : MonoBehaviour
|
||||||
|
|
||||||
var forward = ResolveHeadingForward(heading);
|
var forward = ResolveHeadingForward(heading);
|
||||||
var velocity = forward * (clampedThrottleInput * _speed);
|
var velocity = forward * (clampedThrottleInput * _speed);
|
||||||
_rigid.velocity = velocity;
|
Vector3 targetPos = _rigid.position + velocity * deltaTime;
|
||||||
_rigid.position += velocity * deltaTime;
|
_rigid.MovePosition(targetPos);
|
||||||
|
// _rigid.velocity = velocity;
|
||||||
|
// _rigid.position += velocity * deltaTime;
|
||||||
|
|
||||||
// 调试日志:打印每步计算细节
|
// 调试日志:打印每步计算细节
|
||||||
Debug.Log($"[MoveStep] _speed={_speed} deltaTime={deltaTime:F4} throttle={clampedThrottleInput} " +
|
Debug.Log($"[MoveStep] _speed={_speed} deltaTime={deltaTime:F4} throttle={clampedThrottleInput} " +
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue