Author Topic: Synchronization BUG  (Read 2928 times)

xzkmxd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Synchronization BUG
« on: April 20, 2016, 10:30:27 PM »
Tnet directly continues to move, sometimes shake the situation occurs, why mobile is transform.Translate (Vector3.forward * 5 * Time.deltaTime);

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Synchronization BUG
« Reply #1 on: April 21, 2016, 07:57:38 PM »
I don't understand what you are trying to ask here or what your code snippet is supposed to do.

xzkmxd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Synchronization BUG
« Reply #2 on: April 22, 2016, 09:11:56 AM »
The object is not controlled by the player, but it will always move. There will be a shake of the situation. Or I will send a project to you to see.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Synchronization BUG
« Reply #3 on: April 25, 2016, 01:08:23 PM »
I suggest you post some code instead -- the code you use to send the sync packets for example. The code you pasted simply always moves the object, there is no TNet involved -- so not sure why you would think it would only work on the player-controlled object. It does what you coded it to do.

xzkmxd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Synchronization BUG
« Reply #4 on: May 28, 2016, 01:18:12 PM »
  1. void FixedUpdate()
  2.     {
  3.         transform.position = Vector3.Lerp(StartPos, EndPos, 50 * Time.fixedDeltaTime);
  4.     }
  5.  
  6.     void Start()
  7.     {
  8.         if (tno.isMine)
  9.         {
  10.             GetComponent<MeshRenderer>().material.color = Color.red;
  11.         }
  12.         else
  13.         {
  14.             Destroy(transform.Find("Camera").gameObject);
  15.         }
  16.         StartPos = transform.position;
  17.         EndPos = transform.position;
  18.         //Assets.handling.Game.ClinetPacketCreator.PlayerMove(TNet.TNManager.client, TNet.TNManager.client.playerID, transform.position);      
  19.         StartCoroutine(PeriodicSync());
  20.     }
  21.  
  22.     void Update()
  23.     {
  24.         Debug.Log("isMune:" + isMune);
  25.         if (tno.isMine)
  26.         {
  27.             StartPos = transform.position;
  28.             EndPos = StartPos + new Vector3(0, 0, 5 * Time.deltaTime);
  29.             //transform.position += new Vector3(0, 0, 5 * Time.deltaTime);
  30.            
  31.         }
  32.     }
  33.     #endregion
  34.  
  35.     [TNet.RFC(25)]
  36.     public void UpdateMove(Vector3 start,Vector3 end)
  37.     {
  38.         StartPos = start;
  39.         EndPos = end;
  40.     }
  41.  
  42.     public float updatesPerSecond = 100f;
  43.  
  44.     IEnumerator PeriodicSync()
  45.     {
  46.         for (; ; )
  47.         {
  48.             if (updatesPerSecond > 0f)
  49.             {
  50.                 //if (mList.size != 0 && (!onlyOwnerCanSync || tno.isMine) && Cache()) Sync();
  51.                 //Assets.handling.Game.ClinetPacketCreator.PlayerMove(TNet.TNManager.client, TNet.TNManager.client.playerID, transform.position);
  52.                 tno.Send(25, TNet.Target.OthersSaved, StartPos, EndPos);
  53.                 yield return new WaitForSeconds(1f / updatesPerSecond);
  54.             }
  55.             else yield return new WaitForSeconds(0.1f);
  56.         }
  57.     }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Synchronization BUG
« Reply #5 on: May 29, 2016, 11:26:28 AM »
I'm not sure where to begin with this one...

Your update function adjusts a pair of values, moving one of them by a fixed amount every frame, but only on the player that owns the object. Predictably, other players will not see any real-time movement.

Your PeriodicSync function is executed on all players, meaning they ALL send packets that adjust StartPos and EndPos -- effectively overwriting each other's values all the time.

Each of your players is sending 100 updates per second, completely flooding the network.

Basically everything you're doing there is completely wrong. You are supposed to sending packets only on the player that owns the object. The packets are supposed to be sent infrequently, and only when something changes. If you send more than 10 packets per frame, you are doing something wrong. Each client is supposed to perform local per-frame movement based on the sync'd values. So your update function that only does per-player update shouldn't be checking "tno.isMine" at all.

In short, the bug, or in this case many bugs are in your own code. You need to think through what you're doing.
« Last Edit: May 29, 2016, 11:42:50 AM by ArenMook »