O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Entity rewinding

In order to solve this, we need to store the state of entities at every network update. When the entity needs to be rewound, we find the two states on either end of the target past time, and interpolate between them. This technique actually shares many similarities with the entity interpolation code we wrote in the last chapter, and in some places you could potentially reuse some of the same code.

So, in our network player class, we'll create a new struct to store the network state:

private struct networkState
{
  public Vector3 Position;
  public Vector3 Rotation;
  public Vector3 CamRotation;
  public double Timestamp;
}

We'll keep a buffer of these states, using an array just as in the last chapter:

private networkState[] stateBuffer = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required