- Home /
Inaccurate network position
Hello ! I've put together a small barebone client/server implementation for my project (more likely just a study) and i've been reading about the necessity of some degree of prediction on clients, being a necessity on a larger scale of players/informations traveling the network.
What looks strange to me, is that i'm experimenting an annoying amount of latency, with just two Windows clients running on the same machine. the scene is just a plane where the players prefabs (just cubes with a character controller and a ridiculous simple movement script) are instanced.
and this is my code.
#pragma strict
var server_address:String = "127.0.0.1";
var server_port:int =25001;
var player_prefab : GameObject;
var spawnpos : Vector3;
function Start () {
}
function Update ()
{
}
function OnGUI()
{
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(new Rect(100,100,100,25),"Start Client"))
{
Network.Connect(server_address,server_port);
}
if(GUI.Button(new Rect(100,125,100,25),"Start Server"))
{
Network.InitializeServer(10,server_port,true);
}
}
else
{
if (Network.peerType == NetworkPeerType.Client)
{
GUI.Label(new Rect(100,100,100,25),"Client");
if(GUI.Button(new Rect(100,125,100,25),"Exit"))
{
Network.Disconnect(150);
}
}
if (Network.peerType == NetworkPeerType.Server)
{
GUI.Label(new Rect(100,100,100,25),"Server");
GUI.Label(new Rect(100,125,100,25),"Users : "+Network.connections.Length);
if(GUI.Button(new Rect(100,150,100,25),"Exit"))
{
Network.Disconnect(150);
}
}
}
}
function OnServerInitialized()
{
spawnPlayer();
}
function OnConnectedToServer()
{
spawnPlayer();
}
function OnPlayerDisconnected(player: NetworkPlayer) {
Debug.Log("Clean up after player " + player);
Network.RemoveRPCs(player);
Network.DestroyPlayerObjects(player);
}
function spawnPlayer()
{
spawnpos = Vector3(Random.Range(-3,3),Random.Range(3,5),Random.Range(-3,3));
Network.Instantiate(player_prefab, spawnpos, Quaternion.identity, 0);
}
Now, of course the player prefab has the Network View Component attached to it, observing it's transform, and i already tried setting the State Sync from ReliableDeltaCompressed to Unreliable, with no visible benefit. I'm quite sure that in a few tutorials i've seen online(the ones that guided me writing that script, so basically neither one has any kind of movement prediction/smoothing ) people weren't experimenting such a stuttering movement.
Am I missing something ? I see network scripting is not easy pie, so I may be just overstimating the NetworkView component, and should start writing a proper Client side prediction function, maybe something that would lerp player positions from received RPCs, (while calculating a player average delay) but i have no idea where to start without overcomplicate the whole thing, so i'd really appreciate an example :)
thank you for your time
Your answer
![](https://koobas.hobune.stream/wayback/20220613093146im_/https://answers.unity.com/themes/thub/images/avi.jpg)