- Home /
Multiplayer synchronisation is NOT smooth!
Hey, At the first I´m sorry about my grammar, I´m German :D I have a big problem with my game, everthing works awesome on multiplayer, but the players are not smooth. Here is my multiplayer mainscript:
 using UnityEngine;
 using System.Collections;
 
 public class MPSpawnScript : MonoBehaviour 
 {
 
     public Transform player;
 
     void OnServerInitialized()
     {
         SpawnPlayer();
     }
 
     void OnConnectedToServer()
     {
         SpawnPlayer();
     }
 
     void SpawnPlayer()
     {
         Network.Instantiate(player, transform.position, transform.rotation, 0);
     }
 
     void OnPlayerDisconnected(NetworkPlayer player)
     {
         Network.RemoveRPCs(player);
         Network.DestroyPlayerObjects(player);
     }
 
     void OnDisconnectedFromServer(NetworkDisconnection info)
     {
         Network.RemoveRPCs(Network.player);
         Network.DestroyPlayerObjects(Network.player);
         Application.LoadLevel(Application.loadedLevel);
     }
     
 }
 
Its very simple. And then the playerscript:
 void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
     {
         if (stream.isWriting)
         {
             Vector3 pos = transform.position;
             stream.Serialize(ref pos);
         }
         else
         {
             Vector3 posRec = Vector3.zero;
             stream.Serialize(ref posRec);
             transform.position = posRec;
         }
 
     }
I hope anyone know whats going wrong ^.^
Here is a video: https://www.youtube.com/watch?v=deD6fMeMZw4&feature=youtu.be
Answer by mwbranna · Oct 21, 2014 at 07:59 PM
The game can't send new positions over the network 60 times per second - the default is 15 times per second. Usually, instead of
          stream.Serialize(ref posRec);
          transform.position = posRec;
There will be something like this to smooth it out between network serializations.
          stream.Serialize(ref posRec);
          lerpToThisPosition = posRec;
          ...
          void Update() {
              ...
              transform.position = Vector3.Lerp(transform.position, lerpToThisPosition, 5*Time.deltaTime);
              ...
           }
Your answer
 
 
             Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
NetworkTransform not interpolating? 0 Answers
Network | Math: Smoothly lerp between inconsistent intervals 0 Answers
Network | Math: Smoothly lerp between inconsistent intervals 0 Answers
Client side Player prefab spawned by overriding GameManager return false for isLocalPlayer 0 Answers
