Author Topic: Network.Time - info.timestamp  (Read 4096 times)

Manmax75

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 32
    • View Profile
Network.Time - info.timestamp
« on: September 08, 2013, 02:53:34 AM »
Under recent testing I noticed that my interpolation script was throwing back somewhat jittery movements and I've nailed it down to my interpolation time calculations.

In the default unity networking,
  1. Network.Time - info.timestamp
would bring back the time in transit. It also states that info.timestamp is relative to Network.Time. How can I achieve this in Tnet?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Network.Time - info.timestamp
« Reply #1 on: September 08, 2013, 03:51:46 AM »
Network.time is incredibly unreliable. In Windward I've had it differ drastically between computers (some had their time pass faster than others and other weird stuff like that). In TNet you can use TNManager.ping, but even that is not fully accurate (for obvious reasons).

Packets in TNet don't have any timestamps, so if you need time, you'd have to send the time along with the RFC as one of the parameters.

Masaaki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Network.Time - info.timestamp
« Reply #2 on: September 08, 2013, 11:42:27 AM »
I had need for something like this, so I just threw together my own network time component. It has a Time field, and this is synchronized with an RFC upon joining a game. It's based on the Time.realtimeSinceStartup of the host machine.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class NetworkTime : TNetBehaviour
  5. {
  6.         public static float time = 0f;
  7.  
  8.         void Start()
  9.         {
  10.                 time = Time.realtimeSinceStartup;
  11.         }
  12.  
  13.         void Update()
  14.         {
  15.                 time += Time.deltaTime;
  16.         }
  17.  
  18.         void OnNetworkPlayerJoin( TNet.Player player )
  19.         {
  20.                 if( TNManager.isHosting )
  21.                         tnObject.Send( "SynchronizeTime", player, time );
  22.         }
  23.  
  24.         [TNet.RFC]
  25.         public void SynchronizeTime( float t )
  26.         {
  27.                 float pingSeconds = (float)TNManager.ping / 1000f;
  28.                 NetworkTime.time = t + ( pingSeconds + 0.5f );
  29.         }
  30. }
  31.  

Manmax75

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 32
    • View Profile
Re: Network.Time - info.timestamp
« Reply #3 on: September 14, 2013, 11:53:48 PM »
In case anyone finds this and is looking for a solution, I explained what I did over in my Networking Physics Discussion Thread, here: http://www.tasharen.com/forum/index.php?topic=5788.0