Interpolation vs. Extrapolation
Maintaining networked objects in sync is just one part of the problem when we consider multiplayer games.
One of the prominent issues that arise is the
lag, or other words, the time that takes to update from one player arrives other players, what can lead to jitter movement of characters or even "teleports" in some extreme cases.
In order to mitigate such cases, Photon Bolt implements two strategies with the objective to hide the
lag as much as possible from the game experience: (i) interpolation (interpolated snapshots) and (ii) extrapolation (dead reckoning).
They serve the same basic purpose: Smooth movement of remote player characters on screen, but they do it in vastly different ways.
Bolt has support for these algoritms on certain property types of the entity states, mostly used to synchonize position and/or rotation information, as described below:
Also know as
Interpolated Snapshots (IS), follows a simple principle, works by taking two old but known positions and moving the character between them.
To accomplish this, Bolt maintains a limited historical array of received data (that can represent the position and rotation of an entity, for example), used to compute a smooth transition between the current value and the last valid.
When using this technique to sync the
Transform property of an entity, for instance, the gains consists in that most cases provides a very accurate representation of the world for each player, as in general only already known positions of the remote objects are rendered and in a few cases the entity will be snapped to a position.
The downside of the interpolation is that it requires a delay of the rendering object by some pre-set amount, as the object seen on a client do not represents the most recent value receive, meaning that the player is always behind the real game state (even if this gap is small), this is need to perform the
Also, the algorithm must run on each client for each entity and each property with it enabled, so consider using it with caution.
Extrapolation is another approach used to reduce the perception of non-periodical state updates. This method, called sometimes of
Dead Reckoning (DR), works by taking the last known position, rotation and velocity of a game object, and looking at them, try to predict where the entity is going to be in the future.
If a player sends a packet every third frame, that packet contains the current position, rotation, and velocity of our object, the extrapolation algorithm in Bolt is able to deduce where the object is going be for the next three frames until a piece of new information arrives.
The key factor, in this case, is that if a new packet has not arrived when we have extrapolated to our third frame, we can keep guessing with the same algorithm - sure, the further into the future we guess the more likely it is that we're going to be wrong, but the DR algorithm uses something called projective velocity blending to do corrections when our real data arrives.
The benefit of using extrapolation is that we don't need any artificial delay on our packets, or well - we need very little at least, this lets the game render things faster to the players and does not introduce the same type of artificial lag as the interpolation. It is also a lot better when dealing with games with large player counts, as it handles lost packets or skipped packets (where there was no info for a specific entitiy position, rotation, and velocity) transparently.
The cost of DR is that it's not as precise as IS, and it can be hard to use if you have something like an FPS game where you want to do authoritative and lag compensated shooting, because of the nature of extrapolation (estimation), things might look a bit more different on each player's screen then if you were using interpolated values, which means that you could miss a shot even if you were aiming straight on a player that was moving perpendicular to you.
Selecting The Smoothing Algorithm
When you create a new property of a Bolt Entity State, depending on the property type (listed here), you are able to select one of the available smoothing algorithms:
When selecting the
Interpolation option, there are no extra settings needed to be set, Bolt will take care of the running the algorithm, but when choosing the
Extrapolation technique, some parameters can be changed to properly fill the needs of your game:
- Extrapolation Velocity: this selects from where the velocity of your game object will be gettered or calculated: (i) Calculate from Position difference, (ii) Copy From Rigidbody, (iii) Copy From Rigidbody2D or (iv) Copy From CharacterController components.
- Extrapolation Settings: configure the max number of frames in the future for the estimation and the error tolerance between the predicted value and the actual value, in order to set the data or not, without smooth.