Files
nexus/wiki/concepts/LagCompensation.md
2026-04-26 12:02:53 +08:00

1.3 KiB
Raw Blame History

title, type, tags, sources, last_updated
title type tags sources last_updated
Lag Compensation concept
networking
multiplayer
latency
unity-multiplayer-engineer
2026-04-26

Aliases

  • Server-Side Lag Compensation
  • 延迟补偿

Definition

延迟补偿是一种在服务器权威模型下考虑网络延迟影响的技术。当服务器处理客户端的射击/命中请求时,需要将客户端的请求时间「回溯」到网络延迟对应的时间点,以提供公平的命中判定。

Problem It Solves

在没有延迟补偿的情况下:

  • 客户端 A 看到命中了客户端 B
  • 但由于网络延迟B 已经移动到了新位置
  • 结果A 的命中被服务器拒绝,但 A 看到的是命中效果 → 体验不一致

Standard Approach

  1. 客户端发送带有时间戳的输入/射击请求
  2. 服务器根据网络延迟计算回溯时间
  3. 服务器将目标玩家「回放」到回溯时间点的位置
  4. 在该位置进行命中判定
  5. 结果同步给所有客户端