S&box Wiki

The Game Loop

The Game Loop

Every Tick

Simulate

image.png

Every Tick (60 times a second by default), the client will send a Command to the server. This command gets simulated. This means it takes the inputs from the command (ie, new ViewAngles) and applies them to the Pawn (ie, set rotation to ViewAngles)

While that's being sent to the server the Client also runs the same command locally. This is called Prediction. This allows inputs like walking, shooting and jumping to feel instant, with no ping delay.

After the client runs the command it stores all of the changed entity variables and when the result for that tick comes back from the server it compares them. If they're different then a prediction error happened.

Every Frame

These things are called every frame on the client.

BuildInput

image.png

Every frame we build our input. This converts input from your mouse, keyboard and controller into a Command that can be sent to the server on the next tick.

This is done by passing a InputBuilder class down to the gamemode - which then passes it to the current camera and pawn. These callbacks are generally used to do things like change mouse movement into view angles.

You can override all of this behaviour in your Game class by overriding BuildInput.

BuildCamera

image.png

Every frame we update the camera position. First we find the active Camera (Looking at Client.Camera first, if that was null we use Pawn.Camera) - which sets the position, rotation, fov etc.

After the camera is set up we call Game.PostCameraSetup. This is a useful place to set things up based on camera position, like the viewmodel positions.

Frame Simulate

image.png

Because Simulate only happens once every tick (60fps by default), things like view direction are going to feel pretty shitty clientside. To get around that we call FrameSimulate every frame clientside.

This is commonly used to update things based on view direction (such as Pawn.EyeRot).

It's important to realise that this is clientside only, so if you're setting something here then it needs to be updated in Simulate. If you can't comment out your FrameSimulate code and have the game work normally then you're doing something wrong.

Special Pages


Wikis

?

Render Time: 24ms

DB GetPage 2
Generate Html 0
SaveChanges (1) 18
Render Body 0
Render Sidebar 1