Dynamically Changing Ghosts Between Interpolated and Predicted
Code and workflows to update ghosts between interpolated and predicted
Last updated
Code and workflows to update ghosts between interpolated and predicted
Last updated
We will update Asteroids to be "predicted" when within a specified distance from the player. Although difficult to tell from the gif the Asteroids close to the player are moving smoother than those far away.
Github branch link: https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/tree/Changing-Between-Interpolated-and-Predicted
Currently all the Asteroids are interpolated. That means that the server updates their movement, and then snapshots are sent to the clients to update their position.
You might have noticed that the Asteroids movement is not as "smooth" as it was in our Physics section. The reason is that the client does not get as many update s because of the amount of Asteroids. The server has to send a snapshot for every single Asteroid.
By interpolating all the asteroids, we reduce the computation requirements needed on the client, because they run less physics. So it is a trade-off, do we reduce computation and increase bandwidth?
The answer, like most things in engineering, it depends! For a large scale game, it probably is unnecessary to predicted the physics of everything on the map, especially when the player cannot see/interact with the predicted objects. So in this section we will implement a system that changes which Asteroids are interpolated vs. predicted based on a player's proximity.
First let's make a ClientSettingsAuthoringComponent.cs in Authoring/ to create an authoring component where we will store the radius where Asteroids switch form interpolated to predicted
Let's add this component in ConvertedSubScene on the GameSettings GameObject
Let's set predictionRadius to 5 and predictionRadiusMargin to 1
Now let's create AsteroidSwitchPredictionSystem.cs in Client/Systems
Now let's hit play and check out the difference for Asteroids that are close to the player
The Asteroids that are closer to the player are moving in a smoother fashion! (because they are predicted)
What is great is that this runs on the client side, so the client can make a decision of how much prediction to do
You can imagine you can have settings where lower powered devices run less prediction
We now predict Asteroids that are within our prediction radius
We created the ClientSettingsAuthoringComponent and added it to the GameSettings GameObject in ConvertedSubScene
We created AsteroidSwitchPredictionSystem to use these settings to change nearby Asteroids to predicted from interpolated (and switch back)
Github branch link:
git clone https://github.com/moetsi/Unity-DOTS-Multiplayer-XR-Sample/
git checkout 'Changing-Between-Interpolated-and-Predicted'