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 = Vector3.zero;
if( stream.isWriting )
{
position = transform.position;
stream.Serialize( ref position );
}
else
{
stream.Serialize( ref position );
lastReceivedPosition = position;
}
}
And finally, we'll use the...