Revision Difference
Lag_Compensation#546054
<cat>Code.Network</cat>⤶
<title>Lag Compensation</title>⤶
⤶
# 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⤶
⤶
By default, lag compensation is enabled for all entities that derive from the base addon's Player class. If you want to enable it for any additional entities, such as a custom 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 `WithLagCompensation()` 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.**⤶
⤶
```csharp⤶
var bulletTrace = Trace.Ray( Owner.EyePos, Owner.EyePos + Owner.EyeRot.Forward * 5000f )⤶
.WithLagCompensation()⤶
.UseHitboxes()⤶
.Ignore( Owner )⤶
.Ignore( this )⤶
.Size( radius )⤶
.Run();⤶
```