Why is my player faster on a better PC?

A common s&box bug, and the one idea that fixes it.

Why is my player faster on a better PC?

The problem

Same game. Different speeds.

Your player moves 5 units every frame. Now run that game on three PCs:

Laptop · 30 FPS
150 units / sec
Desktop · 60 FPS
300 units / sec
Gaming PC · 144 FPS
720 units / sec

On the gaming PC the player crosses the map almost 5× faster.

Why it happens

The code counts frames, not seconds.

protected override void OnUpdate(){    WorldPosition += Vector3.Forward * 5f;}

OnUpdate runs once per frame. A faster PC draws more frames, so this line runs more times every second.

The fix

Move per second, not per frame.

s&box tells you how long the last frame took, in seconds. It's called Time.Delta.

distance=speed×Time.Delta

Slow frame, bigger step. Fast frame, smaller step.

The fix in code

Scale the step by Time.Delta.

[Property]public float Speed { get; set; } = 300f; protected override void OnUpdate(){    var step = Speed * Time.Delta;    WorldPosition += Vector3.Forward * step;}

Speed now means units per second. [Property] lets you tune it in the editor.

Proof

Every PC moves 300 units a second.

FPSTime.DeltaPer framePer second
300.033310.00300
600.01675.00300
1440.00692.08300

Bigger steps on slow PCs, smaller steps on fast ones. Same total every second.

The rule

If it changes over time, use Time.Delta.

Moving
+= speed × Time.Delta
Turning
+= turnRate × Time.Delta
Timers
-= Time.Delta

Using Unity? Same rule. It's called Time.deltaTime.