godot-adapt-single-to-multiplayer
Expert patterns for adding multiplayer to single-player games including client-server architecture, authoritative server design, MultiplayerSynchronizer, lag compensation (client prediction, server reconciliation), input buffering, and anti-cheat measures. Use when retrofitting multiplayer, porting to online play, or designing networked gameplay. Trigger keywords: MultiplayerPeer, ENetMultiplayerPeer, SceneMultiplayer, MultiplayerSynchronizer, rpc, rpc_id, multiplayer_authority, client_prediction, server_reconciliation, lag_compensation, rollback.
thedivergentai · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add thedivergentai/GD-Agentic-Skills --skill godot-adapt-single-to-multiplayer技能说明
name: godot-adapt-single-to-multiplayer description: "Expert patterns for adding multiplayer to single-player games including client-server architecture, authoritative server design, MultiplayerSynchronizer, lag compensation (client prediction, server reconciliation), input buffering, and anti-cheat measures. Use when retrofitting multiplayer, porting to online play, or designing networked gameplay. Trigger keywords: MultiplayerPeer, ENetMultiplayerPeer, SceneMultiplayer, MultiplayerSynchronizer, rpc, rpc_id, multiplayer_authority, client_prediction, server_reconciliation, lag_compensation, rollback."
NEVER Do (Expert Multiplayer Rules)
Security & Authority
- NEVER trust client-reported state — Clients own their 'Input', NOT their 'Position' or 'Health'. Server must validate every coordinate and health change.
- NEVER use
get_tree()groups for authority checks — Useis_multiplayer_authority(). Group registration is non-deterministic in high-latency joins. - NEVER allow unrestricted RPC rates — A malicious client can call a 'FireWeapon' RPC 10,000 times per second. Always implement rate-limiting (
net_rpc_rate_limiter.gd).
Movement & Lag
- NEVER skip Client-Side Prediction — Movement without prediction feels 'heavy' and unresponsive. Predict movement locally, then correct only on server disagreement.
- NEVER sync peers at 60Hz — Sending entire state every frame will saturate client bandwidth. Use a lower tick-rate (20-30Hz) and interpolate between packets.
- NEVER snap peer positions — Abrupt position updates cause 'jitter'. Store a buffer of past states and lerp between them with a 100ms delay.
Bandwidth & Sync
- NEVER sync 'Full Floats' if possible — Quantize Vector3 data (truncating decimals) to save 50%+ bandwidth. Use
MultiplayerSynchronizerwith delta-sync enabled. - NEVER ignore 'Late Joiners' — Players who join mid-game won't see existing environmental changes. Broadcast a full world-state 'Snapshot' on peer connection.
- NEVER test on 0ms ping — Everything works on localhost. Use a simulator (
net_latency_simulator.gd) with 150ms ping to identify sync bugs.
Available Scripts
MANDATORY: Architecture decision tree first, then golden-path scripts. Deep latency workflows →
references/latency-testing.md.
Authority / transport bridges
multiplayer_sync.gd
MANDATORY when adding MultiplayerSynchronizer interpolation for remote peers. Trigger: authority owns transforms; non-authority interpolates.
rpc_bridge.gd
MANDATORY signal→RPC bridge. Trigger: gameplay emits local signals; bridge validates authority and fans out RPCs.
Prediction / lag / lobby
net_prediction_reconciliation.gd
CharacterBody prediction + input-buffer replay for server reconciliation.
net_snapshot_interpolation.gd
Snapshot interpolation / jitter buffers for remote peers.
net_auth_server_validator.gd
Authoritative validation (position, speed, actions).
net_rpc_rate_limiter.gd
RPC flood / macro protection.
net_interest_management.gd
Distance-based visibility to cut bandwidth.
net_delta_compression_sync.gd
Quantization + significance checks for delta sync.
net_lag_compensation.gd
Server-side rewind for hit registration.
net_lobby_late_join_sync.gd
Late-joiner world snapshot bootstrap.
Diagnostics
net_latency_simulator.gd
MANDATORY before ship — see references/latency-testing.md.
net_debug_overlay_monitor.gd
RTT / loss / jitter overlay.
net_upnp_discovery_logic.gd
UPNP port mapping for listen-server / P2P hosts.
Architecture Patterns
| Pattern | When | Script golden path |
|---|---|---|
| Authoritative server | PvP, economies, cheat risk | rpc_bridge.gd → net_auth_server_validator.gd → prediction/recon |
| P2P lockstep | 2–4 co-op, low cheat risk | Deterministic inputs + net_upnp_discovery_logic.gd |
| Hybrid / host authority | Party games 4–8 | Host authority + late-join snapshot |
Migration golden path (no inline host/join tutorials)
- Separate input (client) from simulation (authority).
- Set
multiplayer_authorityper player node; clients send intents only. - MANDATORY
multiplayer_sync.gdfor property replication / remote interpolation. - MANDATORY
rpc_bridge.gdfor gameplay events that cross the wire. - Add prediction / lag compensation scripts only for the genres that need them.
- Validate with latency-testing reference +
net_latency_simulator.gdat ~150 ms RTT.
Expert insights (WHY — keep in body)
- Client prediction — WHY: without local sim, RTT doubles perceived input lag. Replay buffered inputs after server correction (net_prediction_reconciliation.gd).
- Interpolation buffer — WHY: raw sync packets jitter; lerp between snapshots with ~100 ms delay (net_snapshot_interpolation.gd).
- Hit rewind — WHY: clients fire at past world state; server rewinds RIDs via
PhysicsServer3Dbefore raycast (net_lag_compensation.gd). - Input send rate — WHY: 60 Hz input RPCs saturate uplink; batch at 20–30 Hz with significance checks (net_delta_compression_sync.gd).
Decision Tree: Which Architecture?
| Factor | Authoritative Server | P2P Lockstep |
阅读完整来源 ↗