Table of Contents

Class LagCompensation

Namespace
Netick.Unity.Pro
Assembly
Netick.Unity.Pro.dll
[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

bool

DrawTreeGizmos

public bool DrawTreeGizmos

Field Value

bool

DrawTreeInternalColor

public Color DrawTreeInternalColor

Field Value

Color

DrawTreeInternalNodes

public bool DrawTreeInternalNodes

Field Value

bool

DrawTreeLeafColor

public Color DrawTreeLeafColor

Field Value

Color

DrawTreeSnapshotSlot

public int DrawTreeSnapshotSlot

Field Value

int

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

inputSource ServerConnection

The 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

hitShape HitShape

The HitShape to sample.

inputSource NetworkPlayer

The player to rewind for.

pos Vector3

The rewound world position of the shape's center.

rot Quaternion

The 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

hitShape HitShape

The HitShape to sample.

tick Tick

The tick to read the stored snapshot for.

pos Vector3

The world position of the shape's center at that tick.

rot Quaternion

The 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

center Vector3

Sphere center, in world space.

radius float

Sphere radius.

hits List<NetHit>

Destination list. Cleared, then filled with every overlap (unordered).

inputSource NetworkPlayer

The player to rewind for.

layerMask int

Layer mask selecting which HitShape layers to test.

includeInputSource bool

When false, the input source's own HitShapes are skipped.

oneHitPerHitShapeContainer bool

When true, at most one hit is reported per container.

filter Predicate<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

shape HitShape

The HitShape to test. Must belong to a live container.

origin Vector3

Ray start, in world space.

direction Vector3

Ray direction. Need not be normalized.

hitData NetHit

The hit, when the method returns true.

inputSource NetworkPlayer

The player to rewind for. See the scene-wide overload.

maxDistance float

Maximum ray length.

includeInputSource bool

When 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

origin Vector3

Ray start, in world space.

direction Vector3

Ray direction. Need not be normalized.

hitData NetHit

The closest hit, when the method returns true.

inputSource NetworkPlayer

The player to rewind for — pass the shooting player's input source. Null (or a non-server caller) resolves against the latest interpolated world.

maxDistance float

Maximum ray length.

layerMask int

Layer mask selecting which HitShape layers to test.

includeInputSource bool

When false, the input source's own HitShapes are skipped.

filter Predicate<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

origin Vector3

Ray start, in world space.

direction Vector3

Ray direction. Need not be normalized.

hits List<NetHit>

Destination list. Cleared, then filled with every hit (unordered).

inputSource NetworkPlayer

The player to rewind for.

maxDistance float

Maximum ray length.

layerMask int

Layer mask selecting which HitShape layers to test.

includeInputSource bool

When false, the input source's own HitShapes are skipped.

oneHitPerHitShapeContainer bool

When true, at most one hit is reported per container.

filter Predicate<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

origin Vector3

Center of the sphere at the start of the sweep, in world space.

direction Vector3

Sweep direction. Need not be normalized.

radius float

Sphere radius.

hitData NetHit

The closest hit, when the method returns true.

inputSource NetworkPlayer

The player to rewind for.

maxDistance float

Maximum sweep distance.

layerMask int

Layer mask selecting which HitShape layers to test.

includeInputSource bool

When false, the input source's own HitShapes are skipped.

filter Predicate<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

origin Vector3

Center of the sphere at the start of the sweep, in world space.

direction Vector3

Sweep direction. Need not be normalized.

radius float

Sphere radius.

hits List<NetHit>

Destination list. Cleared, then filled with every hit (unordered).

inputSource NetworkPlayer

The player to rewind for.

maxDistance float

Maximum sweep distance.

layerMask int

Layer mask selecting which HitShape layers to test.

includeInputSource bool

When false, the input source's own HitShapes are skipped.

oneHitPerHitShapeContainer bool

When true, at most one hit is reported per container.

filter Predicate<HitShapeContainer>

Optional predicate to reject candidate containers before testing.