Class LagCompensation
[ExecutionOrder(1500)]
public sealed class LagCompensation : INetickComponent
- Inheritance
-
LagCompensation
- Implements
- Inherited Members
Constructors
LagCompensation()
public LagCompensation()
Fields
Compensate
Master switch for server-side rewind. When false, queries resolve against the latest interpolated world for every input source instead of rewinding to each one's perceived tick. HitShape capture and the snapshot ring keep running either way.
public bool Compensate
Field Value
DrawTreeGizmos
public bool DrawTreeGizmos
Field Value
DrawTreeInternalColor
public Color DrawTreeInternalColor
Field Value
- Color
DrawTreeInternalNodes
public bool DrawTreeInternalNodes
Field Value
DrawTreeLeafColor
public Color DrawTreeLeafColor
Field Value
- Color
DrawTreeSnapshotSlot
public int DrawTreeSnapshotSlot
Field Value
Methods
CanRewind(ServerConnection)
Returns whether the server can rewind for this connection - true only on the server when the connection has a current input to derive the rewind tick from. When false, queries for this source resolve against the latest interpolated world instead.
public static bool CanRewind(ServerConnection inputSource)
Parameters
inputSourceServerConnectionThe connection to test.
Returns
- bool
True if a rewound query is possible for this connection.
FetchHitShapePosAndRot(HitShape, NetworkPlayer, out Vector3, out Quaternion)
Returns the lag-compensated world position and rotation of a HitShape as
the inputSource perceived it — i.e. the same rewound, interpolated
pose a query for that player would test against. Useful for spawning hit FX or debug
gizmos that line up with the rewound world.
public void FetchHitShapePosAndRot(HitShape hitShape, NetworkPlayer inputSource, out Vector3 pos, out Quaternion rot)
Parameters
hitShapeHitShapeThe HitShape to sample.
inputSourceNetworkPlayerThe player to rewind for.
posVector3The rewound world position of the shape's center.
rotQuaternionThe rewound world rotation of the shape.
FetchHitShapePosAndRot(HitShape, Tick, out Vector3, out Quaternion)
Returns the world position and rotation a HitShape had at an exact
historical tick, read straight from the snapshot ring with no
interpolation. The tick must still be within the ring (within MaxRewindTime).
public void FetchHitShapePosAndRot(HitShape hitShape, Tick tick, out Vector3 pos, out Quaternion rot)
Parameters
hitShapeHitShapeThe HitShape to sample.
tickTickThe tick to read the stored snapshot for.
posVector3The world position of the shape's center at that tick.
rotQuaternionThe world rotation of the shape at that tick.
NetworkFixedUpdate()
public void NetworkFixedUpdate()
NetworkRender()
public void NetworkRender()
OverlapSphere(Vector3, float, List<NetHit>, NetworkPlayer, int, bool, bool, Predicate<HitShapeContainer>)
Collects every HitShape overlapping a lag-compensated sphere into
hits (cleared first). Same rewind behavior as the cast queries.
public void OverlapSphere(Vector3 center, float radius, List<NetHit> hits, NetworkPlayer inputSource, int layerMask = -1, bool includeInputSource = false, bool oneHitPerHitShapeContainer = false, Predicate<HitShapeContainer> filter = null)
Parameters
centerVector3Sphere center, in world space.
radiusfloatSphere radius.
hitsList<NetHit>Destination list. Cleared, then filled with every overlap (unordered).
inputSourceNetworkPlayerThe player to rewind for.
layerMaskintLayer mask selecting which HitShape layers to test.
includeInputSourceboolWhen false, the input source's own HitShapes are skipped.
oneHitPerHitShapeContainerboolWhen true, at most one hit is reported per container.
filterPredicate<HitShapeContainer>Optional predicate to reject candidate containers before testing.
Raycast(HitShape, Vector3, Vector3, out NetHit, NetworkPlayer, float, bool)
Casts a lag-compensated ray against a single, specific HitShape and returns whether it was hit. Skips the broadphase entirely — use this when you already know which shape you want to test (e.g. a re-validation pass).
public bool Raycast(HitShape shape, Vector3 origin, Vector3 direction, out NetHit hitData, NetworkPlayer inputSource, float maxDistance = Infinity, bool includeInputSource = false)
Parameters
shapeHitShapeThe HitShape to test. Must belong to a live container.
originVector3Ray start, in world space.
directionVector3Ray direction. Need not be normalized.
hitDataNetHitThe hit, when the method returns true.
inputSourceNetworkPlayerThe player to rewind for. See the scene-wide overload.
maxDistancefloatMaximum ray length.
includeInputSourceboolWhen false, returns false if the shape belongs to the input source.
Returns
- bool
True if the shape was hit.
Raycast(Vector3, Vector3, out NetHit, NetworkPlayer, float, int, bool, Predicate<HitShapeContainer>)
Casts a lag-compensated ray against every HitShape in the scene and
returns the closest hit. The world is rewound to the snapshot pair the
inputSource was interpolating when the input was produced, so the
hit matches what that player saw on screen.
public bool Raycast(Vector3 origin, Vector3 direction, out NetHit hitData, NetworkPlayer inputSource, float maxDistance = Infinity, int layerMask = -1, bool includeInputSource = false, Predicate<HitShapeContainer> filter = null)
Parameters
originVector3Ray start, in world space.
directionVector3Ray direction. Need not be normalized.
hitDataNetHitThe closest hit, when the method returns true.
inputSourceNetworkPlayerThe player to rewind for — pass the shooting player's input source. Null (or a non-server caller) resolves against the latest interpolated world.
maxDistancefloatMaximum ray length.
layerMaskintLayer mask selecting which HitShape layers to test.
includeInputSourceboolWhen false, the input source's own HitShapes are skipped.
filterPredicate<HitShapeContainer>Optional predicate to reject candidate containers before testing.
Returns
- bool
True if a HitShape was hit.
RaycastAll(Vector3, Vector3, List<NetHit>, NetworkPlayer, float, int, bool, bool, Predicate<HitShapeContainer>)
Casts a lag-compensated ray against every HitShape in the scene and
collects all hits into hits (cleared first). Same rewind behavior
as Raycast(Vector3, Vector3, out NetHit, NetworkPlayer, float, int, bool, Predicate<HitShapeContainer>).
public void RaycastAll(Vector3 origin, Vector3 direction, List<NetHit> hits, NetworkPlayer inputSource, float maxDistance = Infinity, int layerMask = -1, bool includeInputSource = false, bool oneHitPerHitShapeContainer = false, Predicate<HitShapeContainer> filter = null)
Parameters
originVector3Ray start, in world space.
directionVector3Ray direction. Need not be normalized.
hitsList<NetHit>Destination list. Cleared, then filled with every hit (unordered).
inputSourceNetworkPlayerThe player to rewind for.
maxDistancefloatMaximum ray length.
layerMaskintLayer mask selecting which HitShape layers to test.
includeInputSourceboolWhen false, the input source's own HitShapes are skipped.
oneHitPerHitShapeContainerboolWhen true, at most one hit is reported per container.
filterPredicate<HitShapeContainer>Optional predicate to reject candidate containers before testing.
SphereCast(Vector3, Vector3, float, out NetHit, NetworkPlayer, float, int, bool, Predicate<HitShapeContainer>)
Sweeps a lag-compensated sphere of radius along a ray and returns
the closest hit. Same rewind behavior as Raycast(Vector3, Vector3, out NetHit, NetworkPlayer, float, int, bool, Predicate<HitShapeContainer>).
public bool SphereCast(Vector3 origin, Vector3 direction, float radius, out NetHit hitData, NetworkPlayer inputSource, float maxDistance = Infinity, int layerMask = -1, bool includeInputSource = false, Predicate<HitShapeContainer> filter = null)
Parameters
originVector3Center of the sphere at the start of the sweep, in world space.
directionVector3Sweep direction. Need not be normalized.
radiusfloatSphere radius.
hitDataNetHitThe closest hit, when the method returns true.
inputSourceNetworkPlayerThe player to rewind for.
maxDistancefloatMaximum sweep distance.
layerMaskintLayer mask selecting which HitShape layers to test.
includeInputSourceboolWhen false, the input source's own HitShapes are skipped.
filterPredicate<HitShapeContainer>Optional predicate to reject candidate containers before testing.
Returns
- bool
True if a HitShape was hit.
SphereCastAll(Vector3, Vector3, float, List<NetHit>, NetworkPlayer, float, int, bool, bool, Predicate<HitShapeContainer>)
Sweeps a lag-compensated sphere of radius along a ray and collects
all hits into hits (cleared first).
public void SphereCastAll(Vector3 origin, Vector3 direction, float radius, List<NetHit> hits, NetworkPlayer inputSource, float maxDistance = Infinity, int layerMask = -1, bool includeInputSource = false, bool oneHitPerHitShapeContainer = false, Predicate<HitShapeContainer> filter = null)
Parameters
originVector3Center of the sphere at the start of the sweep, in world space.
directionVector3Sweep direction. Need not be normalized.
radiusfloatSphere radius.
hitsList<NetHit>Destination list. Cleared, then filled with every hit (unordered).
inputSourceNetworkPlayerThe player to rewind for.
maxDistancefloatMaximum sweep distance.
layerMaskintLayer mask selecting which HitShape layers to test.
includeInputSourceboolWhen false, the input source's own HitShapes are skipped.
oneHitPerHitShapeContainerboolWhen true, at most one hit is reported per container.
filterPredicate<HitShapeContainer>Optional predicate to reject candidate containers before testing.