N4: Lag-compensated hit validation
A network client draws other players in the past and its commands take time to arrive, so by the time the server fires a shot the target has moved on: 8 ticks at a 50 ms round trip, 12 at 200 ms. Each PlayerCommand now carries view_lag: how far back its player was seeing everyone else, in quarter ticks. The simulation keeps where every player's body has been for the last 15 ticks (HitHistory), and a hitscan shot is traced against other players where they were at the moment the shooter saw, and against the world as it is now. Projectiles aren't rewound. The client claims only when it was looking and where it aimed; the server works out the hit from its own record. The moment is never more than Tuning.LAG_COMPENSATION_MAX_TICKS back, never in the future, and never earlier than a moment the same player has already claimed. Commands are 15 bytes, so the command log's version is 2. The lag is in the log, and replays judge every shot as the match did. Measured in test/net/test_lag_compensation_link.gd over a simulated link: a client firing at a walking target as drawn on its own screen hits 41 of 41 shots at 50, 100 and 200 ms round trips, 0 of 41 with the lag ignored, and 0 of 41 at 500 ms, past the cap. Closes #35 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -434,6 +434,10 @@ const WEAPONS: Dictionary = {
|
||||
"spread": 0.0, "bloom": 0.0,
|
||||
},
|
||||
}
|
||||
## A network client sees other players late. The server judges a hitscan shot against
|
||||
## where they were when the shooter saw them, going back at most this many ticks (half
|
||||
## a second). Past that the shooter has to lead the target.
|
||||
const LAG_COMPENSATION_MAX_TICKS: int = 15
|
||||
## Spread multiplier while aiming, unless a weapon sets its own `aim_spread`.
|
||||
const AIM_SPREAD_FACTOR: float = 0.4
|
||||
## Extra spread while moving, and while airborne or swimming, in degrees.
|
||||
|
||||
Reference in New Issue
Block a user