S&box Wiki

Lag Compensation


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.


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


Within Simulate you can do using ( LagCompensation() ) { } and within that scope the transforms of all eligible entities will be lag compensated. This means any traces or physics queries you run within that scope will yield the rewound positions and rotations for those entities.

By default, the BaseWeapon class included in the base addon already has PrimaryAttack and SecondaryAttack enclosed in a block just like this.