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

37 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Lag Compensation"
type: concept
tags: [networking, multiplayer, latency]
sources: [unity-multiplayer-engineer]
last_updated: 2026-04-26
---
## Aliases
- Server-Side Lag Compensation
- 延迟补偿
## Definition
延迟补偿是一种在服务器权威模型下**考虑网络延迟影响**的技术。当服务器处理客户端的射击/命中请求时,需要将客户端的请求时间「回溯」到网络延迟对应的时间点,以提供公平的命中判定。
## Problem It Solves
在没有延迟补偿的情况下:
- 客户端 A 看到命中了客户端 B
- 但由于网络延迟B 已经移动到了新位置
- 结果A 的命中被服务器拒绝,但 A 看到的是命中效果 → 体验不一致
## Standard Approach
1. 客户端发送带有**时间戳**的输入/射击请求
2. 服务器根据网络延迟计算**回溯时间**
3. 服务器将目标玩家「回放」到回溯时间点的位置
4. 在该位置进行命中判定
5. 结果同步给所有客户端
## Related Concepts
- [[ServerAuthority]]: 延迟补偿依赖服务器权威
- [[ClientPrediction]]: 两者结合提供流畅且公平的游戏体验
- [[AntiCheatArchitecture]]: 延迟补偿同时是反作弊的重要手段
## Related Entities
- [[UnityMultiplayerEngineer]]: 实现延迟补偿的专家
- [[UnrealMultiplayerArchitect]]: 虚幻引擎中的对应实现