Creating a networked object
Before we can apply interpolation or prediction, we'll need a base to build off of. We'll create a networked object which can be moved around via arrow keys. We'll start with absolutely no interpolation whatsoever—the object instantly appears at the newest location received over the network.
First, let's create a very simple player script.
using UnityEngine; using System.Collections; public class Player : MonoBehaviour { public float MoveSpeed = 5f; void Update() { if( networkView == null || networkView.isMine ) { transform.Translate( new Vector3( Input.GetAxis( "Horizontal" ), 0, Input.GetAxis( "Vertical" ) ) * MoveSpeed * Time.deltaTime ); } } }
This script is very basic. It simply checks if the network view belongs to the local player (or does not exist), and if so it moves the transform with the horizontal and vertical axes (in Unity, by default these correspond to WASD and arrow key pairs, as well as left thumb stick axes on many...