Class LagCompensationRegistry
Server-side registry of CharacterPositionHistory, and the scoped rewind that resolves a hit against where characters were rather than where they are.
public static class LagCompensationRegistry
- Inheritance
-
LagCompensationRegistry
- Inherited Members
Remarks
How to use it. Wrap a spatial query in a using block. The scope displaces every eligible character in the scene, keeps them displaced for the body, and puts them back on dispose — including when the body throws, which is the whole reason it is a scope rather than a pair of calls.
using (LagCompensationRegistry.Rewind(scene, target, caster))
{
hitCount = physicsScene.OverlapSphere(center, radius, hits, mask, QueryTriggerInteraction.UseGlobal);
}
Scene-scoped on purpose. Characters are indexed by scene handle because each scene runs its own UnityEngine.PhysicsScene. Rewinding every character on the server for a query that can only hit one scene would be both wasteful and wrong.
The caster is never rewound. A shooter aims from where it is now, not where it was, so displacing it would move the origin of its own query.
Fields
RewindReach
How far a character can have been from where it stands now at any moment a rewind may reach back to, metres: the margin a bounded rewind adds round its query so nobody who could have been in it is left out.
public const float RewindReach = 20
Field Value
Methods
AnyWithin(Scene, Vector3, float)
True when any character registered in scene stands within reach metres of
point across the ground (x and z): what lets something that only matters to a character near it
(a ship's hull collider, FloatingBoats) stand down where none is. Its current transform, never a rewound one.
public static bool AnyWithin(Scene scene, Vector3 point, float reach)
Parameters
sceneScenepointVector3reachfloat
Returns
RegisteredIn(Scene)
Number of characters registered in a scene. For diagnostics and tests.
public static int RegisteredIn(Scene scene)
Parameters
sceneScene
Returns
Rewind(Scene, RewindTarget, ICharacter)
Displaces every character in scene to where it was at
tick, until the returned scope is disposed.
public static LagCompensationRegistry.RewindScope Rewind(Scene scene, RewindTarget target, ICharacter exclude = null)
Parameters
sceneSceneScene whose characters should be rewound.
targetRewindTargetexcludeICharacterCharacter to leave in place — normally the caster.
Returns
Rewind(Scene, RewindTarget, ICharacter, Vector3, float)
Rewind(Scene, RewindTarget, ICharacter), for a query that only looks within
radius of center: only the characters standing within that radius plus
RewindReach are moved.
public static LagCompensationRegistry.RewindScope Rewind(Scene scene, RewindTarget target, ICharacter exclude, Vector3 center, float radius)
Parameters
sceneScenetargetRewindTargetexcludeICharactercenterVector3radiusfloat
Returns
Remarks
Every step of every player-cast object rewound EVERY character in the scene and synced physics twice, to test a segment a few decimetres long. A character farther away than it could have travelled in the rewind window cannot be in the query at either position, so it is left where it stands; and when nobody is near, nothing is moved and nothing is synced at all.