stabilize dead air camera reconciliation
All checks were successful
build / image (push) Successful in 27s

This commit is contained in:
Syncer Deploy
2026-08-31 13:21:31 -04:00
parent 6361ecbdd7
commit 6c345ba595
4 changed files with 54 additions and 7 deletions

View File

@@ -203,11 +203,36 @@ export function useDeadAirClient(): DeadAirClientView {
const localAfter = (engine.currentState as DeadAirClientState).players.find(
(player) => player.id === engine.localPlayerId,
);
if (localBefore && localAfter && decoded.snapshot.state.round === renderSource.current.state.round) {
if (
localBefore &&
localAfter &&
localBefore.alive === localAfter.alive &&
decoded.snapshot.state.round === renderSource.current.state.round
) {
const now = performance.now();
const correction = renderSource.current.localCorrection;
correction.x += localBefore.x - localAfter.x;
correction.z += localBefore.z - localAfter.z;
correction.updatedAt = performance.now();
const decay = Math.exp(-(now - correction.updatedAt) / 115);
const leadSeconds = clock.interpolationAlpha / deadAirGame.tickRateHz;
const deltaX =
localBefore.x + localBefore.velocityX * leadSeconds -
localAfter.x - localAfter.velocityX * leadSeconds;
const deltaZ =
localBefore.z + localBefore.velocityZ * leadSeconds -
localAfter.z - localAfter.velocityZ * leadSeconds;
if (Math.hypot(deltaX, deltaZ) < 3) {
correction.x = correction.x * decay + deltaX;
correction.z = correction.z * decay + deltaZ;
} else {
correction.x = 0;
correction.z = 0;
}
correction.updatedAt = now;
} else {
renderSource.current.localCorrection = {
x: 0,
z: 0,
updatedAt: performance.now(),
};
}
break;
}