Search Unity

[RELEASED] Smooth Sync - Smoothly network rigidbodies and transforms while reducing bandwidth

Discussion in 'Assets and Asset Store' started by Fuestrine, Aug 4, 2017.

  1. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    46
    Nothing in particular:
    1. I had no idea there was a newer version
    2. "If it works don't fix it"
     
  2. SteYippee

    SteYippee

    Joined:
    Sep 5, 2018
    Posts:
    1
    @Fuestrine

    I was wondering whether you've had chance to look further into the issue that @MustangLM was facing, as I'm having the exact same problem.

    The issue does seem to be related to the camera in some way, as the jittering effect is more noticeable when vehicles are travelling side by side. In terms of my project, it is going to be running on LAN only, so I don't know whether that gives me any options for really pushing what's being sent through the network in order to try and produce a smoother result, as the latency is going to be lower.

    In the meantime I will be experimenting with lower send rates/higher interpolation values to see how smooth things can look in that sense.
     
  3. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @SteYippee
    I have sent you the experimental velocity driven syncing version in a PM. Let me know how it goes.
     
  4. peterpantss

    peterpantss

    Joined:
    Sep 24, 2014
    Posts:
    9
    I upgraded to unity 2018.3b2 and smoothsync gives me the error 'Assets\Plugins\Smooth Sync\HalfHelper.cs(3,22): error CS0234: The type or namespace name 'Remoting' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?)'
    Any ideas how to fix?
     
  5. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @en4ian
    No clue. I don't really support beta versions of Unity either, I'd rather wait for it to be stable and released.

    Try not using compression if you are getting an error with HalfHelper though. If you get that problem without running the game, get rid of those lines in HalfHelper. Let me know if that doesn't solve it.
     
    Last edited: Sep 22, 2018
  6. desukarhu

    desukarhu

    Joined:
    Jun 14, 2017
    Posts:
    12
    Hi!

    I'm trying to get SmoothSync to work with Photon. I saw this snippet having a lot of trouble getting this to work. Could you help me out how to get it to work? I pasted it into SmoothSync.cs but there were a bunch of errors, I tried fixing them but the error with "networkState.smoothSync.lastTeleportOwnerTime" missing stumped me.
     
  7. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @desukarhu
    I don't use lastTeleportOwnerTime any more so you can get rid of that conditional. Look at the HandleSync methods for what I do around .addState() these days, but you might be fine after getting rid of lastTeleportOwnerTime anyway as the validation methods aren't really needed.
     
  8. winter13

    winter13

    Joined:
    Sep 25, 2018
    Posts:
    1
    Hello,

    Could you please help me how to use smooth sync with nodejs websocket. I think n nodejs server will be relay all data sync from the component, but I dont know how to implement it. I dont use UNet.

    Thank you.
     
  9. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @winter13
    Smooth Sync "runs using Unity's high-level networking API" but it should be able to work with some other networking API I would think.

    Check out https://forum.unity.com/threads/rel...reducing-bandwidth.486605/page-2#post-3283440 where I show how to start changing to Photon. It's basically just creating a byte array (which you should be able to send over any networking system) and then sending it. Then you'll receive the byte array and convert it to be usable by Smooth Sync.

    At the end of SendState() is where I send stuff out. You should be able to receive and Smooth Sync will automatically work if you add the state with AddState().

    Let me know if you run into any issues.
     
    Last edited: Sep 26, 2018
  10. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    793
    Just uploaded new and improved video to the store page. Check it out.

     
  11. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    46
    Hi,

    Is there any example of how to use teleport? My current issue is that when clients teleport, server keeps interpolating making them travel all across the map and getting hit by enemies in the process.

    Also in the example, all I see related to teleport is this small part
    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.T))
    2.         {
    3.             transform.position = transform.position + Vector3.right * 10;
    4.             smoothSync.teleport();
    5.         }
    But this is not working 100% of the times (interpolation still happens on some cases) and sometimes players will show up in the middle of the map (trajectory from where they teleported to the destination) because they hit collides on the path

    Also, is this bit updated? http://grabblesgame.com/smoothsync/...h_sync.html#a3218f7be5d12d30af9eca5402c49feb0
     
    Last edited: Oct 11, 2018
  12. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @Alkanov
    Yeah, you should be able to just call 'teleport()' but I am seeing it interpolating sometimes too. Thanks for bringing it to my attention. I'll PM you a copy when I'm done. I'd guess tomorrow or the next day.

    I do need to update the docs it looks like. I'll do that when I put this new update out.

    EDIT: I think you commented that you were on an older version too. I'll tell you what the changes are so you can implement them in your version if you want.
     
    Last edited: Oct 12, 2018
  13. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    46
    Hi, for some reason I never had this issue with the older version, it was only after I updated to the newer version when this started to happen.

    Thank you, let me know if there is anything else I can help you with.
     
  14. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
  15. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    Smooth Sync Version 3.05 has been submitted to the Asset Store. The changes are as follows:
    • Fixed issue with teleporting not teleporting during FPS drops.
    • Added drop-in PUN and PUN2 solutions with full example scenes.
    • Added smoothing on authority ownership changes.
    • Added optional velocity driven syncing where Smooth Sync uses the synced position to determine what to set the velocity to on unowned objects. Requires a rigidbody. This will produce smoother results at faster speeds and was made for games like flying or racing. It is less accurate than default Smooth Sync. Things can also go wrong if the position is blocked that it is trying to get to. You should set a "Snap Position Threshold" if you use this.
     
  16. Alkanov

    Alkanov

    Joined:
    May 15, 2017
    Posts:
    46
    Hi, I used the code you sent me and the first time I hit play I got this issue (not sure if this one is related to the interpolation one): Client teleported fine, but on server it didnt move

    I have tried to replicate it but no luck
     
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @Alkanov
    I just tried for awhile and I didn't see the issue once. I also tried changing some settings but never saw the issue. The teleport issue I fixed earlier was easy to replicate, I used a ton of output so the FPS would be lower than the sendRate and then it would not teleport correctly.

    If it didn't move for you at all and you never saw the issue again, it could be due to it being Unrealiable (instead of Reliable). https://docs.unity3d.com/ScriptReference/Networking.Channels.html
    Which brings up a good point that I shouldn't have changed teleport to not use a reliable RPC for teleporting since it is more important than a typical position update.

    As a quick fix, you can change the Network Channel to 0, which is Unity's Reliable network channel. This will make it worse though as every time it drops a message (pretty low chance really) it will try to send it again.
    Another fix for this would be setting "SnapPositionThreshold" so that if you teleport and it doesn't send, it will Snap and Teleport the next time it moves.
    These are both bad fixes though and I'll definitely just be switching back to a reliable RPC instead of sending it over the stream.

    If you've seen it more than very rarely, the next step would be sending me a screenshot of your settings so I can try to replicate the issue using those.

    So yeah, let me know if you've seen it more than once or if you've only seen it once and then I'll have a better idea of what is happening.
     
    Last edited: Oct 13, 2018
  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @Alkanov
    You can scratch that wall of text and just set the Network Channel to 0 (Reliable) and it should fix your issue. Let me know if it doesn't.

    You might see some hiccups though if your interpolation back time is low. You'll be able to put it back to 1 (Unreliable) when I'm done fixing teleport() to be sent on a Reliable channel. I'll let you know when I get that done.
     
  19. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    Version 3.06 submitted to the Asset Store.

    Change log:
    • Teleport is now sent on a reliable network channel.
     
    Last edited: Oct 15, 2018
  20. jh-ham

    jh-ham

    Joined:
    Feb 11, 2015
    Posts:
    1
    Can support PUN and PUN2 ? If support, remove "photon viewer" component?
     
  21. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @jh-ham
    Yes, it works for PUN and PUN2. I have full example scenes too for PUN and PUN2 but you use it just like you would hook up any script in Photon Networking. I believe you need the PhotonView component though as that is what allows network messages to get sent across the network in Photon. Correct me if I'm wrong though as I'm not too skilled in Photon.

    Let me know if you have further questions or if I misunderstood.

    Note: If using PUN2, the EasingSpeeds should be .85 on the SmoothSyncPlayerPrefabPUN2. The script defaults will be automatically .85 when you put it on your object anyway but I'll update the example scene in the next update.
     
    Last edited: Oct 20, 2018
  22. Arsonide

    Arsonide

    Joined:
    Nov 16, 2009
    Posts:
    39
    Since you are supporting Photon now, what are the chances of getting a version that supports Mirror?

    Mirror is basically UNET except the community has picked it up to fix bugs and optimize it. I followed the migration guide and it took me like five minutes to swap out SmoothSync from UNET to Mirror. So I already have a version of SmoothSync for it, but an officially supported one would be awesome.

    Edit: I also have it in a private repository, if you'd like to see the diffs shoot me a PM.
     
    Last edited: Oct 21, 2018
  23. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @Arsonide
    I'll keep it in mind but it's most likely a no for me. PUN and PUN2 already jumped my SmoothSync script versions up to four. Mirror also doesn't seem to have a preprocessor directive so that'd be a whole new script I'd have to upkeep and another UnityZipFile thing to take care of. I don't think it'd entice many other people to buy it as Mirror doesn't seem to have a large number of users either.

    Thanks for the suggestion though, feel free to reach out again any time.
     
  24. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    @Fuestrine
    I'm having a similar jittering issue when travelling parallel to another synced object. I tried upgrading to 3.06 and using the new velocity sync feature, but it caused the object to lag too far behind. Here is a clip of a SmoothSync-ed cylinder without velocity sync enabled

     
  25. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    @Fuestrine
    I was able to tinker with the code a little and get the synced object moving more smoothly. In
    applyInterpolationOrExtrapolation
    I interpolate a max distance instead of Lerping 85% (or whatever
    actualPositionLerpSpeed
    is set to).

    Something like this -
    Code (CSharp):
    1.  
    2. float maxDist = lerpMaxDist * Time.fixedDeltaTime;
    3. Vector3 newPos = SOGO.moveTowards(getPosition(), newPosition, maxDist);
    4. setPosition(newPos, shouldTeleport);
    Where SOGO.moveTowards moves a max distance

    Code (CSharp):
    1. public static Vector3 moveTowards(Vector3 from, Vector3 to, float maxMove)
    2.     {
    3.         Vector3 vec = to - from;
    4.         float offset = vec.magnitude;
    5.         if (Mathf.Abs(offset) > maxMove)
    6.         {
    7.             vec = vec.normalized * maxMove;
    8.             Vector3 dest = from + vec;
    9.             return dest;
    10.         }
    11.         else
    12.         {
    13.             return to;
    14.         }
    15.     }
     
  26. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    I am actually seeing some strangeness here now. I'll take a deeper look at what's going on and get back to you.
     
    Last edited: Oct 23, 2018
  27. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    Thanks @Fuestrine !

    Here is a video of a fresh project with all the default settings (except
    WhenToUpdate 
    set to
    FixedUpdate
    , though
    Update
    was just as bad)

     
  28. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    Lowering your TimeCorrectionSpeed should help, set to basically 0 to test to see if it helps at all. Then raise it to your liking. .0001-.0005 can get you pretty smooth while still being reactive to changes in latency. Also, compression should be off by default, but I don't know if you just copied the prefab example over which has them on, but turning compression off will help.

    It seems both are bad for you, but for the Update / FixedUpdate, make sure your camera script, and probably your movement script since it probably just follows the player, is updating in the same one that you set WhereToUpdateTransform at. It will look wonky if your character (and by extension the camera) is only updating in FixedUpdate() and your SmoothSynced object is only updating in Update().

    I'm still not seeing it as good as I'd want it though so I'm going to need another night of going through and getting a deeper look. I'll message you tomorrow or the next day.
     
    Last edited: Oct 25, 2018
  29. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    Are those capsules 1 unit? Which would make the grid 1 unit squares?

    I'm just trying to get a sense of scale here as I'm not seeing as much twitching on my end until way higher speeds.

    Try out the low TimeCorrectionSpeed and make sure compression is off.
    Also try a lower SendRate if that's not enough(12 should be good for an InterpolationBackTime of .1). This is because if you check the velocity (local movement only) every frame, you'll see a high variance but as you lengthen your time, you'll get more accurate velocity (checking velocity on local movement object, not networked at all).

    Let me know how it goes.

    If that doesn't help, is there any way you can send me your project so I can see exactly what is going on?
     
  30. dariorigon

    dariorigon

    Joined:
    Oct 27, 2018
    Posts:
    3
    Hey there, i am trying to make a simple bumper car game with physics, but i want the physics to happen just in the server. Just bought smooth sync and i love it. But i have a problem.

    When i start the game as server everything work fine and i can drive the car.
    When i start the game as client i can drive the car (through the client) and see it move on the server, and interact with the server car, but on the client itself the client car is frozen, but i can see the server car moving..

    When in server view i go against the client car (client view position), the client car teleport to its frozen position, and then it is completely frozen.

    I am doing something wrong probably.

    The thing is:
    i am using commands to move the cars in the sever, but in the clients their positions is not updated.

    What i am doing wrong? Working on this for 2 days..

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class bumperCar : NetworkBehaviour {
    7.  
    8.     public bool isDriver;
    9.     public float CustomCarSpeed;
    10.     public float CustomCarBackwardSpeed;
    11.     public float CustomCarRotation;
    12.     [SyncVar]
    13.     public int CarEnergy = 5;
    14.     [SyncVar]
    15.     public float actualRotation;
    16.     [SyncVar]
    17.     public float actualSpeed;
    18.  
    19.     // Use this for initialization
    20.     void Start () {
    21.         if (isServer) {
    22.             print ("Sono il Server!");
    23.             gameObject.GetComponent<ConstantForce> ().enabled = true;
    24.         }
    25.  
    26.     }
    27.  
    28.     // Update is called once per frame
    29.     void Update () {
    30.         /*
    31.         //Energia Esaurita  
    32.         if (CarEnergy < 1) {
    33.             //l'energia resta a zero
    34.             CarEnergy = 0;
    35.  
    36.             //non si può più guidare
    37.             isDriver = false;
    38.  
    39.             //il motore si spegne
    40.             CmdResetCarEngine ();
    41.         }
    42.         */
    43.         if (isLocalPlayer) {
    44.             Drive ();
    45.         }
    46.         if (!isServer) {
    47.             gameObject.GetComponent<ConstantForce> ().enabled = false;
    48.             gameObject.GetComponent<Rigidbody> ().Sleep();
    49.         }
    50.         if (isServer) {
    51.             PhysicDrive ();
    52.         }
    53.     }
    54.  
    55.     void Drive(){
    56.  
    57.         CmdResetCar ();
    58.  
    59.         if(Input.GetButton("TurnLeft")){
    60.  
    61.             CmdSetRotation(-CustomCarRotation);
    62.         }
    63.  
    64.         if(Input.GetButton("TurnRight")){
    65.  
    66.             CmdSetRotation(CustomCarRotation);
    67.         }
    68.  
    69.         if(Input.GetButton("GoBackward")){
    70.  
    71.             CmdSetSpeed(-CustomCarBackwardSpeed);
    72.         }
    73.  
    74.  
    75.     }
    76.  
    77.     void PhysicDrive(){
    78.  
    79.         Vector3 carRotation = new Vector3(0,actualRotation,0);
    80.         Vector3 carSpeed = new Vector3(0,0,actualSpeed);
    81.  
    82.         //velocità default
    83.         gameObject.GetComponent<ConstantForce> ().relativeTorque = Vector3.zero;
    84.         gameObject.GetComponent<ConstantForce> ().relativeForce = Vector3.zero;
    85.  
    86.         gameObject.GetComponent<ConstantForce> ().relativeTorque = carRotation;
    87.         gameObject.GetComponent<ConstantForce> ().relativeForce = carSpeed;
    88.  
    89.     }
    90.  
    91.     [Command]
    92.     void CmdResetCarEngine (){
    93.  
    94.         gameObject.GetComponent<ConstantForce> ().relativeForce = Vector3.zero;
    95.         gameObject.GetComponent<ConstantForce> ().relativeTorque = Vector3.zero;
    96.  
    97.     }
    98.  
    99.     void    OnCollisionEnter (Collision collision){
    100.  
    101.             foreach (ContactPoint contact in collision.contacts) {
    102.                 if (isDriver) {
    103.                     if (contact.otherCollider.tag == "Bumper" && contact.thisCollider.tag == "CarBody") {
    104.                     CmdRemoveLife ();
    105.                     }
    106.                 }
    107.                 return;
    108.             }
    109.         }
    110.  
    111.     [Command]
    112.     void CmdRemoveLife(){
    113.         CarEnergy -= 1;
    114.     }
    115.  
    116.     [Command]
    117.     void CmdSetRotation(float rotation){
    118.         actualRotation = rotation;
    119.     }
    120.  
    121.     [Command]
    122.     void CmdSetSpeed(float speed){
    123.         actualSpeed = speed;
    124.     }
    125.     [Command]
    126.     void CmdResetCar(){
    127.         actualRotation = 0;
    128.         actualSpeed = CustomCarSpeed;
    129.     }
    130. }
    131.  
     
  31. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    Hi @Fuestrine,

    I'm still not having any luck reducing the jitter.

    The capsule is the default (unscaled) size. I have tried moving/syncing in both
    Update 
    and
    FixedUpdate
    , and I've tried having the camera attached directly to the player and following via script in
    FixedUpdate/Update/LateUpdate
    . I also tried a lower
    TimeCorrectionSpeed 
    and a lower
    SendRate 
    without success.

    Is it possible I'm moving my rigidbody in a way such that velocity isn't synced? I have a non-kinematic rigidbody on my player object and I've tried moving using
    transform.Translate
    and just directly setting
    transform.position
    .

    I'd be happy to send my simple reproducer project! What's the best way to get it to you?
     
    Last edited: Oct 28, 2018
  32. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2

    Steps to fix your project:
    • Reset Smooth Syncs to default. Lower TimeCorrectionSpeed to .0001 (or higher or lower, but .0001 will start you off pretty Smooth)
    • On your custom movement script, uncheck MoveInFixedUpdate.
    This video shows the results, except I changed ChangeDirTime to 5 on your server player object custom movement script so that I could see it lining up better.

    Host is bottom-right window.



    Let me know how it goes or if you have any questions.
     
  33. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @dariorigon
    I think your problem is that SmoothSync syncs uses the owner to determine the position. In your case, your player is owned locally by a client. You'll need to move it locally (on the owner) and then it will sync to all other computers.

    If you want to make your car owned by the server, your best bet is probably to set up some type of PlayerController that is owned locally so you can send your drive Commands over to the server. Then the PlayerController on the server would know which car to send that information to. Then the car would drive on the server and the position will be sent to all other computers.

    Let me know if I misunderstood or if you have more questions.
     
  34. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    @Fuestrine that seems a lot smoother. Is there any way to get smoother behavior while updating player position in FixedUpdate()? I'm using a character controller that moves in that step
     
  35. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    I don't see any way to make it possible. It doesn't do much different between FixedUpdate() and Update(). You can look for WhenToUpdate in the code and see the exact differences though. It seems to just be a limitation of how FixedUpdate() and Update() work in Unity.

    You can try lowering your Fixed Timestep, or converting your Character Controller to Update() are the only ideas I have.

    Let me know if you think it's a limitation with SmoothSync but I don't see any solution regarding Smooth Sync. All I can do is update in one of the update methods and FixedUpdate() isn't going to be as smooth as Update().
     
  36. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    Version 3.07 is now on the Asset Store.

    Changes:
    • IMPORTANT: If updating, look at new default (.05) for TimeCorrectionSpeed. How it is used has changed. .3 in new speed is about .01 in old speed.
    • Fixed teleport from rest issue.
    • PUN and PUN2 interpolate smoother.
     
  37. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    A new version is on the Asset Store now. It's not going to help with your FixedUpdate() Update() problem but you inspired me to change TimeCorrectionSpeed a bit. If you update, I'd try around a .02 probably with the new way I handle correcting time. It can now correct faster while being smoother.

    I'll think it over with the Update() FixedUpdate() problem but I just don't think a solution is possible regarding changing Smooth Sync. I've been wrong many times before though.
     
    Last edited: Oct 29, 2018
  38. davebutlerenator2

    davebutlerenator2

    Joined:
    Nov 8, 2014
    Posts:
    26
    @Fuestrine
    I'll check it out! As always thanks for the great support/help
     
  39. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @davebutlerenator2
    I'll be poking around some more tomorrow. The issue has piqued by interest to see exactly why it doesn't work at least, even if it just improves my knowledge of Unity.
     
  40. dariorigon

    dariorigon

    Joined:
    Oct 27, 2018
    Posts:
    3

    Thank you for your answer! The problem was exactly that. Disabling player authority did the trick. Now the server does the physics and the clients just update their position based on that. This plugin is amazing in doing so!
     
  41. mflux

    mflux

    Joined:
    Oct 19, 2017
    Posts:
    7
    Hey @Fuestrine thanks for the plugin. My client is an automotive company and we're making a multi-user unity app synced over the network. I'm experiencing the same issue as all of the people above where the camera attached to a smoothsynced object will experience jitter.

    The behavior is really strange. It will be smooth for a period of time, then desync in bursts:



    Here are smoothsync settings for all cars on the road:



    My setup:
    • Testing on local host (built+editor, or built+built)
    • All cars are driven server-side (including the car player is sitting in). No transformation is being changed on client side (should it? prediction..?)
    • Cars have no rigid body. They are driven by advancing a variable (distance along road) and the road gives them their new position and orientation per Update.
    • Player has a camera component. Player uses transform.SetParent and sets one of the cars as Parent. I've tried both adding an extra smoothsync->child object, and not doing that, same result. Should the child also have a smoothsync component?

    Things I've noticed:
    • All synced objects are smooth, so long as camera is not attached to a smoothsynced object
    • It happens with all cars simultaneously, but only noticeable when cars are close to you
    • Everything is smooth if the camera is simply not attached to a car

    Things I've tried:
    • Added second smoothsync to car to target child object (because the cars are made of body and wheels, the parent is merely a transform with network id). Does not work.
    • Adding a second smoothsync for the player object. Does not work.
    • Turning off compression, turning time correction to 0.001, increasing interpolation back time, adjusting tween values. Does not work.
    • Tried velocity driven syncing but I'm not sure if I'm using it correctly since my driving code is not velocity-driven.
    Would appreciate some help with this thank you!
     
    Last edited: Oct 30, 2018
  42. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @mflux
    Thanks for the detailed write up! I'm not seeing this issue in the example scene though but my setup may be a little different.
    Here's a video with your setup the best I could recreate. It's hard to see without a background but I'm moving forward at 30 units/second (67 mph). Let me know if you think I missed something in trying to recreate the issue.


    All Smooth Sync settings are reset to default except TimeCorrectionSpeed is 0.0001
    The server controls the position of both of the "cars" as they travel forwards at 30 u/s (67mph). Only Smooth Sync is setting the position of the "cars" on the client. The camera is a child of the "car" too. There is only one Smooth Sync for each "car".

    I'll send you the full example scene I'm using and details on replicating in a PM.

    About how fast are your cars going when this happens for you? In units per second.

    I would confirm that you are indeed setting position only on the server as it kind of looks like Smooth Sync is trying to fight something else for control of the position.

    Some other thoughts, but looking at the project I sent you and seeing how it's different than what you are doing is probably your best bet:
    One thing may be that you are hitting your SnapTimeThreshold, but I wouldn't expect constant jitter, I'd expect a single jump. Try setting that number really high and see if the jitter happens less.

    If raising SnapTimeThreshold helps, see if you can raise your TimeCorrectionSpeed while not gaining any jitter. The variable numbers I gave out earlier are probably too low for the current way I handle TimeCorrectionSpeed. (I think you have the newest version judging from one of your variable defaults.)

    If all objects are only moving on the server and that position is being sent to all clients then I don't think prediction would help here. Also, I don't think having the cars locally controlled would fix this issue.

    No, the child should not need a Smooth Sync component in this scenario. It should be syncing exactly along with the car already if I understand you correctly.

    Ah yes, I need to change the comments on this one probably. Thanks for bringing it to my attention.
    It doesn't need to be velocity driven on the position determination side. You should just need a rigidbody on it on non-owners (clients in your case). It will then try to set the velocity so that everything looks smooth and in sync since the physics (and position) is basically determined entirely locally. Probably turn off the rigidbody on the owner (server for you) or it might mess with you trying to change position to drive the car though.
    This setting was an attempt at getting super fast things (200mph+) to not have any jitter. I would think you wouldn't need to use this but it might work. It's less accurate though, and may be a little wonky. I kind of hesitated to put it in but I made it for someone awhile back and they haven't had any issues with it yet.

    Let me know if I missed or misunderstood anything, or if you have further questions.
     
    Last edited: Oct 31, 2018
  43. kraken22

    kraken22

    Joined:
    Oct 21, 2017
    Posts:
    4
    Hi Fuestrine,
    I just bought the asset and i am very impressed with the performance. Definitely worth the money. However, I can only get the movement to sync if the script is on a GameObject controlled by the player. ie the GameObject is spawned with NetworkServer.SpawnWithClientAuthority(). When I spawn my prefab using NetworkServer.Spawn() the syncing does not work. (This GameObject is controlled by an AI script which is run on the server) Is there a setting I missed or does this not work.

    Thanks a lot
     
  44. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @kraken22
    Hi. I don't think you missed any Smooth Sync settings. It works for me using default Smooth Sync settings.

    Steps to recreate:
    Open Smooth Sync Example.
    Uncheck Auto Create Prefab on the NetworkManager. (just to unclutter up the playing space)
    Make a script with the code below to spawn an object.
    Hook up the SmoothSyncPlayerPrefab to objectToSpawn in the inspector to your new script.
    Uncheck local player authority on SmoothSyncPlayerPrefab.
    Code (CSharp):
    1. public GameObject objectToSpawn;
    2.     // Update is called once per frame
    3.     void Update ()
    4.     {
    5.         if (Input.GetKeyDown(KeyCode.V))
    6.         {
    7.             GameObject newObj = Instantiate(objectToSpawn);
    8.             NetworkServer.Spawn(newObj);
    9.         }
    10.     }
    Use the arrow keys on the server to move the object around. It is synced to the clients.

    Let me know how it goes or if you think I misunderstood your request.
     
  45. kraken22

    kraken22

    Joined:
    Oct 21, 2017
    Posts:
    4

    Wow thank you for the quick reply. I just tested it in the example scene and it works as you described.
    Then I noticed that the AI tanks that were controlled on the server still had local player authority checked (from a script). Quickly disabled that and Smooth sync works perfectly. 100% recommend to anyone looking to sync their GameObjects over the network.
     
  46. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @kraken22
    Great to hear that it's working for you. If you like the plugin and my support, every five star rating helps us get noticed a bit more. :)
     
  47. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    40
    @Fuestrine in 3.07 the velocity-driven code that sets the RB's velocity (line 1016) only sets the 3D RB, doesn't check for a 2D RB

    It's easy to fix locally, just FYI
     
  48. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    40
    @Fuestrine
    Also having an issue where when my players spawn, the client moves wayy behind the server, and it gradually gets better and better until they match up. I'm guessing this is related to the new TimeCorrectionSpeed thing, but I'm using the standard value of 0.05. If I set it to 0.3 it definitely catches up faster, but it's still way behind when spawned.

    All my settings:
    https://i.imgur.com/6LLtIf8.png
     
  49. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    431
    @foolmoron
    Thanks for bringing it to my attention. For the TimeCorrectionSpeed, one other fix might be to change FORCE_TIME_SYNC_DURATION to 1.5f, an older setting. This will auto set the time for a bit at the beginning. I'll take a deep look at it under some different networks, .05 could be too low for default.

    Also, I'm not sure if you were the one who requested smooth authority changes, but I just finished fixing that up too. This TimeCorrectionSpeed thing is the only thing I have left to look at then I'll have a new version available.
     
  50. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    40
    Yup that was me, was happy to see that in the changelogs!

    FYI I was testing entirely locally with this. One instance was a build, one was the editor. Usually that works super well because the latency is near 0.
     
unityunity