Adding naive interpolation

First, let's add the simplest form of entity interpolation. We'll simply store the position of the object received over the network, and in Update we simply lerp to the new position. This is the interpolation we used in the first chapter when creating the Pong clone.

First, we'll create a temporary variable to hold values received over the network.

private Vector3 lastReceivedPosition;

We'll initialize this to the current position in Start.

void Start()
{
  lastReceivedPosition = transform.position;
}

In our OnSerializeNetworkView function, we'll store our received value in this variable, rather than directly assigning transform position.

void OnSerializeNetworkView( BitStream stream, NetworkMessageInfo info ) { Vector3 position ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.