N4 Lag-compensated hit validation #35

Closed
opened 2026-11-09 05:28:15 +00:00 by claude · 1 comment
Owner

Depends on: N3, B6

Rewind hitboxes on the server to validate shots against what the client saw, within a capped window.

Acceptance

  • Tests cover accuracy at 50, 100 and 200 ms, and rejection beyond the cap.
  • A client cannot claim hits it could not have made.
**Depends on:** N3, B6 Rewind hitboxes on the server to validate shots against what the client saw, within a capped window. **Acceptance** - Tests cover accuracy at 50, 100 and 200 ms, and rejection beyond the cap. - A client cannot claim hits it could not have made.
claude added this to the v0.5 Multiplayer milestone 2026-11-09 05:28:15 +00:00
claude added the priority/hightype/feature labels 2026-11-09 05:28:15 +00:00
claude added this to the Tidewall v1.0 project 2026-11-09 15:00:08 +00:00
eric closed this issue 2026-11-12 16:45:28 +00:00
Author
Owner

Done in 5e1704e.

What changed

  • PlayerCommand has a new field, view_lag (u8, quarter ticks): how far back from the command's tick its player was seeing everyone else. Commands are now 15 bytes and the command log is version 2. ClientGame fills it in from its interpolation clock; bots and local play send 0.
  • src/sim/hit_history.gd: where every player's body has been (position and height) for the last 15 ticks.
  • Weapons: a hitscan shot is traced against other players where they were at the moment the shooter saw, between ticks if need be, and against terrain, props and built pieces as they are now.
  • Tuning.LAG_COMPENSATION_MAX_TICKS = 15 (half a second).

A client cannot claim hits it could not have made. The client never says "I hit". It says when it was looking and where it aimed, and the server works out the rest from its own record. The claim is bounded three ways: never more than the cap back, never the future, and never earlier than a moment the same player has already claimed, so nobody can fire at the past and the present by turns and keep whichever hits.

How it was tested
make check passes (426 tests, self-check, smoke) and make match still replays to the same hash.

End to end (test/net/test_lag_compensation_link.gd): a client behind a simulated link fires a signal revolver once a second at the middle of a target walking across at 4 m/s, 25 m away, aiming at where its own interpolator draws it.

Round trip Rewind the client asked for Hits, lag honoured Hits, lag ignored
50 ms 8.0 ticks 41 of 41 0 of 41
100 ms 9.5 ticks 41 of 41 0 of 41
200 ms 11.8 ticks 41 of 41 0 of 41
500 ms 20.8 ticks, past the cap 0 of 41

In the simulation (test/sim/test_lag_compensation.gd, 10 tests): hits at 6, 9.25, 12.5 and 15 ticks back and misses for the same aim judged in the present; claims of 30 ticks and of 255 quarter ticks judged at the cap; a sudden claim of the past not believed; a wall built since stops the shot; a target eliminated since isn't hit; a target that was crouched then has no head at standing height; same commands, same state hash.

Limits worth knowing

  • I read "50, 100 and 200 ms" as round trips. The rewind a client needs is the round trip plus about 7 ticks (4 of interpolation delay, 3 of command margin), so the cap covers round trips up to roughly 300 ms. Past that the shooter has to lead.
  • Projectiles (the whaler's longgun) fly in the server's present and aren't rewound. The boathook isn't either; H9 (#73) is about it not damaging players at all.
  • A player being shot can be hit just after getting behind cover on their own screen, by up to the shooter's rewind. That is the usual price of this technique, and the cap is what bounds it.
  • All of this is headless arithmetic over a simulated link. Whether shooting feels right is for the playtest.
Done in 5e1704e. **What changed** - `PlayerCommand` has a new field, `view_lag` (u8, quarter ticks): how far back from the command's tick its player was seeing everyone else. Commands are now 15 bytes and the command log is version 2. `ClientGame` fills it in from its interpolation clock; bots and local play send 0. - `src/sim/hit_history.gd`: where every player's body has been (position and height) for the last 15 ticks. - `Weapons`: a hitscan shot is traced against other players where they were at the moment the shooter saw, between ticks if need be, and against terrain, props and built pieces as they are now. - `Tuning.LAG_COMPENSATION_MAX_TICKS` = 15 (half a second). **A client cannot claim hits it could not have made.** The client never says "I hit". It says when it was looking and where it aimed, and the server works out the rest from its own record. The claim is bounded three ways: never more than the cap back, never the future, and never earlier than a moment the same player has already claimed, so nobody can fire at the past and the present by turns and keep whichever hits. **How it was tested** `make check` passes (426 tests, self-check, smoke) and `make match` still replays to the same hash. End to end (`test/net/test_lag_compensation_link.gd`): a client behind a simulated link fires a signal revolver once a second at the middle of a target walking across at 4 m/s, 25 m away, aiming at where its own interpolator draws it. | Round trip | Rewind the client asked for | Hits, lag honoured | Hits, lag ignored | |---|---|---|---| | 50 ms | 8.0 ticks | 41 of 41 | 0 of 41 | | 100 ms | 9.5 ticks | 41 of 41 | 0 of 41 | | 200 ms | 11.8 ticks | 41 of 41 | 0 of 41 | | 500 ms | 20.8 ticks, past the cap | 0 of 41 | | In the simulation (`test/sim/test_lag_compensation.gd`, 10 tests): hits at 6, 9.25, 12.5 and 15 ticks back and misses for the same aim judged in the present; claims of 30 ticks and of 255 quarter ticks judged at the cap; a sudden claim of the past not believed; a wall built since stops the shot; a target eliminated since isn't hit; a target that was crouched then has no head at standing height; same commands, same state hash. **Limits worth knowing** - I read "50, 100 and 200 ms" as round trips. The rewind a client needs is the round trip plus about 7 ticks (4 of interpolation delay, 3 of command margin), so the cap covers round trips up to roughly 300 ms. Past that the shooter has to lead. - Projectiles (the whaler's longgun) fly in the server's present and aren't rewound. The boathook isn't either; H9 (#73) is about it not damaging players at all. - A player being shot can be hit just after getting behind cover on their own screen, by up to the shooter's rewind. That is the usual price of this technique, and the cap is what bounds it. - All of this is headless arithmetic over a simulated link. Whether shooting feels right is for the playtest.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: claude/tidewall#35