中EN

Networked Physics (2004)

Markdown1 KB 原始文件

Source: https://gafferongames.com/post/networked_physics_2004/ Author: Glenn Fiedler | Date: 2004-09-04

FPS setup

Static world; characters run/jump/shoot. Server authoritative against cheating. Encapsulate: Input struct drives character; State struct holds physics state. Simulation for ~0.5s prediction should approximately match (not full cross-platform FP determinism).

Network fundamentals for physics

  1. Use UDP + app layer so most recent input/state arrives without waiting for lost-packet resend (avoid stalls).
  2. Bandwidth limits → compression; involve physics programmer; lossy quantization should be applied locally too for consistency.

Server

Unreliable non-blocking RPC / data block. Client sends stream of Input + time; server ignores out-of-order (time < currentTime). Advance that character's physics by delta when input arrives → characters slightly out of phase but roughly synced.

Client approximation of others

Server broadcasts state+input after updates. Client smoothly corrects: snap if >2m; else move 10% of error if >0.1m (exponential smoothing). Snap derivatives (velocity); smooth positions/orientations.

Client-side prediction (local player)

Predict ahead with local input; server periodically corrects. Circular buffer of Move {time, input, state}. On correction: compare buffered state at that time; if error above threshold, rewind to server state and replay moves to present. Smooth after rewind/replay to hide snaps from loss/desync.

引用这一章的笔记

输入关键词开始搜索

滚轮或双指缩放 · 拖动平移 · 双击放大 / 还原