Author Topic: One frame of lag when joining a channel  (Read 1855 times)

Proton

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
  • Alberta, Canada
    • View Profile
    • Time Gamers
One frame of lag when joining a channel
« on: December 22, 2016, 08:58:54 PM »
I captured a video of what I mean: https://gfycat.com/ThunderousDearCaimanlizard

For 1 frame the player in Channel 60 is in the wrong spot (the spot where he spawned). But it doesn't happen every time.

I confirmed the packets are being processed in the correct order and all on the same frame.

It turned out the ExampleCar.SetRB RFC was only setting the Rigidbody Pos & Rot, but the TNAutoCreate.CreateAtPosition RCC was setting the Transform Pos & Rot.

Setting the Transform Pos & Rot in the SetRB RFC seems to fix it. I'm guessing the rigidbody only updates the transform on the FixedUpdate, that would explain why it wouldn't happen sometimes.

TNSyncRigidbody is the same (saw the same behavior with the cubes).

Hope this helps someone!

BTW, I recently switched from Photon to TNet and am very impressed! Server-side persistence wasn't something I thought I needed until I saw it. It feels like a bunch of possibilities opened up ;D

Proton

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
  • Alberta, Canada
    • View Profile
    • Time Gamers
Re: One frame of lag when joining a channel
« Reply #1 on: December 22, 2016, 09:18:12 PM »
(I don't see an edit post option, so new reply it is)
Another thought, it might be good to only sync the transform the first time the RFC is called. Changing transforms directly on rigidbodies can cause them to explode if they collide :o

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: One frame of lag when joining a channel
« Reply #2 on: December 24, 2016, 11:35:16 PM »
I've actually ran into a curious issue in my current game project regarding setting rigidbody / transform positions of objects that are still being loaded. Seems Unity treats them differnetly if the rigidbody is kinematic. I had weird things happening and changed the script on my end.
  1.         [RFC(1)]
  2.         void OnSync (Vector3 pos, Quaternion rot, Vector3 vel, Vector3 ang)
  3.         {
  4.                 if (mRb.isKinematic)
  5.                 {
  6.                         mTrans.position = pos;
  7.                         mTrans.rotation = rot;
  8.  
  9.                         // Does this actually do anything? Needs to be investigated...
  10.                         mRb.isKinematic = false;
  11.                         mRb.velocity = vel;
  12.                         mRb.angularVelocity = ang;
  13.                         mRb.isKinematic = true;
  14.                 }
  15.                 else
  16.                 {
  17.                         if (TNManager.IsJoiningChannel(tno.channelID))
  18.                         {
  19.                                 mTrans.position = pos;
  20.                                 mTrans.rotation = rot;
  21.                         }
  22.                         else
  23.                         {
  24.                                 mRb.position = pos;
  25.                                 mRb.rotation = rot;
  26.                         }
  27.  
  28.                         mRb.velocity = vel;
  29.                         mRb.angularVelocity = ang;
  30.                 }
  31.                 UpdateInterval();
  32.         }