Interpolation of player's position over RPC calls

Hi guys!

So I’m trying to establish my first game that utilizes the Network, so please bear with me :stuck_out_tongue:

I’m trying to set a Server with full authority. The clients, in order to make movements, pass the information of motion unto the server, who then communicates the changes made, towards the clients.

I think I have done this correctly, but now I have run into the problem of jittering. I have tried somethings to make the jitter less prominent through modification of the timestep, send rate and assigning function to the LateUpdate.

But I guess that there is no way to make the movement smooth if I don’t do interpolation.

So I guess the question is this>

If I’m using the following RPC to move the player (In this case a RotateAround), how could I do interpolation?

Is this an incorect view to update the players position? Is there a simpler way

I dont really understand all the things that are already written on the internet, :((

Any help much appreciated :D, Its hard being self taught : /

var target : Transform; 
var haveControl : boolean = false;


function Update()

{
	if(haveControl)
	{
		if(Network.isClient)
		{	
	
			var MouseY : float = Input.GetAxis("Mouse X");	
			networkView.RPC("MoveMouseToServer", RPCMode.Server, MouseY);	
		}
	}
}

function LateUpdate () {
	
	if (Network.isServer)
	{
		networkView.RPC("updatePlayer", RPCMode.OthersBuffered, transform.position);
		networkView.RPC("updatePlayerRot", RPCMode.OthersBuffered, transform.rotation);	
	}
}

@RPC
function MoveMouseToServer(MouseY : float){

	transform.RotateAround(target.transform.position, Vector3.up, MouseY*3);
}

@RPC
function updatePlayer(playerPos : Vector3){
	transform.position = playerPos;
}
 
@RPC
function updatePlayerRot(playerRot : Quaternion){
 	transform.rotation = playerRot;
 }

Any Ideas?

Is there a way to do something like Lerp, the actual position, with the information that is being received from the server when they do>

	networkView.RPC("updatePlayer", RPCMode.OthersBuffered, transform.position);
	networkView.RPC("updatePlayerRot", RPCMode.OthersBuffered, transform.rotation);	

Is there a way to set a variable with the information that is being received via RPC?

Have a variable LastReceive representing the last time you got the positional update then a LastReceiveDelta representing the last time it took to get another positional update. Also have the LastPosition which is the last positional update you’re interpolating from and store the new positional update in NewPosition. Then…

void Update()
{
transform.position = Vector3.lerp(LastPosition, NewPosition,
(Time.time - LastReceive) / LastReceieveDelta);
}

[RPC] PositionalUpdate(Vector3 UpdatedPos)
{
LastPosition = NewPosition;
NewPosition = UpdatedPos;
LastReceiveDelta = Time.time - LastReceive;
LastReceieve = Time.time;
}

You were right! It was not. My camera had the same script, but it was a child of an object, who had itelf to deal with RPC calls!

Thanks for the help buddy :smiley: