Skip to main content

Client-side Prediction

When players are far away from each other, there is a delay between when the player sends an action and when another receives it. Easel attempts to hide this delay using client-side prediction, making the game feel more responsive.

When the prediction is wrong, Easel attempts to smooth out the corrections in a way that the player might not notice. There are some steps you can do to increase the likelihood the prediction will be correct, and to minimize the jarring effects of corrections when the prediction is wrong. This page details these techniques.

tip

See Rollback Netcode to learn more about how multiplayer in Easel works under the hood.

Acceptable input latency

Client-side prediction is only used when the input latency is higher than an acceptable threshold. If your game can accept more input latency, for example if it is a slower-paced turn-based game, then you can configure Easel to accept a higher input latency. This avoids client-side prediction altogether, avoiding any issues with mispredictions. See [network] configuration for more details.

Rubberbanding

Easel uses rubberbanding to smooth out the differences between the predicted game state and the actual game state. Instead of sudden jumps which may be jarring, characters will smoothly move to their correct positions. These corrections sometimes are so subtle they become unnoticeable.

To ensure Easel can rubberband all graphics in your game, make sure to assign an Entity with a Body to the body parameter when using a graphical function like PolygonSprite or Spark. Avoid using a Vector position directly because only Body positions can be smoothed by Easel. Use the screenOffset or bodyOffset parameters to adjust the position if necessary.

Slotted random

Instead of having one global random number generator, Easel has one per-entity, and you can even explicitly define more if you want. This makes it less likely that order-of-execution will affect the random numbers generated, and more likely the prediction will be correct if the inputs change due to a rollback. The current this entity is automatically discovered from context and so normally this just works out of the box, but if you are generating random numbers outside of an entity context, consider passing in a this parameter explicitly to Random.

See Random for more details.