S&box Wiki

Lag Compensation

Lag Compensation

Introduction

Lag compensation happens server-side during Simulate and essentially rewinds lag compensated entities to the position they were in when the client being simulated sent their input commands. This means that traces will hit entities that the client would expect to be hit from their point-of-view.

Enabling

If you want to enable it for any entities, such as a pawn, you can simply set the LagCompensation property to true on that entity. This is usually does in the entity's Spawn method.

Traces

Within Simulate you can call UseLagCompensation() on any trace to enable lag compensation for that trace and any subsequent traces until the end of the simulation.

Example Usage

The following code could be used within a weapon's PrimaryAttack method. This is because PrimaryAttack is called within Simulate and so this trace would be lag compensated.

Note: all subsequent traces will also be affected by lag compensation until the end of the simulation.

var bulletTrace = Trace.Ray( Owner.EyePos, Owner.EyePos + Owner.EyeRot.Forward * 5000f ) .UseLagCompensation() .UseHitboxes() .Ignore( Owner ) .Ignore( this ) .Size( radius ) .Run();

Special Pages


Wikis

?

Render Time: 13ms

DB GetPage 3
Generate Html 0
SaveChanges (1) 6
Render Body 0
Render Sidebar 1