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

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 ...

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