Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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

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

  1. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @camirving
    Ah yeah, it's because it's a child. It's weird that UNet and Mirror don't spawn child objects at the right locations but they spawn the parent object at the right location.

    I think I see a solution but I'll have to finish it up tomorrow. I'll message you tomorrow with the solution unless things go horribly wrong.
     
  2. camirving

    camirving

    Joined:
    Jan 20, 2014
    Posts:
    33
    Sweet! Thank you!

    Please hit me up when you manage to come up with a fix.
     
  3. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
  4. toyhunter

    toyhunter

    Joined:
    Mar 5, 2018
    Posts:
    34
    @Fuestrine
    Now I'm switching my project to Photon from UNet, please advise if SmoothSync is capable working with Photon? Thanks a lot :)
     
  5. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @hmpublic2000
    Yep, Smooth Sync has PUN and PUN2 packages in it. Unpackage whichever one you are using and then just use SmoothSyncPUN or SmoothSyncPUN2 like normal.

    If you are switching to Photon for connectivity issues, we just released a similar product called Noble Connect. It's priced about 16% cheaper plus you should have less chance of going over their/our bandwidth limits since we attempt to connect directly whenever possible.
     
    Last edited: Mar 22, 2019
    toyhunter likes this.
  6. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    4
    Hello! Could you please help with the following setup:
    • two clients (host + client)
    • UNET
    • client authority for players
    • client authority for non-player object (rigidbody), initially set authority to host
    • authority of non-player object switched by distance to players (the nearest requests authority)
    • player and non-players objects have "Smooth Sync" for network transform.
    Problem is in rigidbody (non-player) jerking at the moment of switch authority (visible on client which loose his authority). Sometimes rigidbody stepback at position and sometimes rotation is changed to one from previous frames.
    "Smooth Authority Changes" is checked. Seems rigidbody is not syncing for a long time between clients w/o "Smooth Authority".
    I tried to play with "Interpolation Back Time" 0 - 0.3 (default 0,1) - the larger the value the worse result i got. The same for "Extrapolation".

    Please tell me if some sources will help (they are very simple).
    And if possible, plz provide any links to tutorial/paper/github/youtube where AssignClientAuthority + ClientRpc is described. Found many times forum threads about to call ClientRpc for all clients after change of authority, but w/o any details.
     
  7. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @oleg_v
    I think what you are seeing is normal and that's just what's going to happen when you change authority. The object is literally in a different position on other screens because of latency and InterpolationBackTime. So when someone takes over authority, they take it over at the current position on their screen, which is "ping + InterpolationBackTime + a couple frames" different from the current owner. So you are correct that raising InterpolationBackTime would make it even further off because it is putting it that much time in the past on purpose to create a buffer for lag spikes. Lower InterpolationBackTime to see less of a difference in position between the two game instances.

    Extrapolation shouldn't be messing with anything here unless your InterpolationBackTime is really low and your Extrapolation is really low (or if you are using ExtrapolationDistance and your speed is very high).

    I'm not really sure what you are asking for as far as ClientRpcs and AssignClientAuthority being described. You should be able to call ClientRpcs like normal after you change authority of objects. Smooth Sync wouldn't be getting in the way of this at least.

    Let me know if I misunderstood anything or if you have any questions.
     
  8. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    4
    Thank you!
    Finally I set InterpolationBackTime to -0.1 and it solve "jumping" problem with authority change, but rigidbody physics looks weird on client w/o authority (i.e. rigidbody smoothly falling through the ground prior to bounce, anyway its looking better :).
    Another problem I see in future is a fast change of authority when players are "fighting" for shared rigidbody.

    Probably its a normal behaviour, but not in my case:
    • each player must see shared rigidbody w/o any lags when he has interaction with rigidbody
    • each player see each other and shared rigidbodies all the time
    No "jumping" is allowed and users are expecting smooth game.
    Currently can't imagine how to solve this problem.
    Any ideas appreciated :)

    Question about ClientRpc is following: what should I manually send to clients from server after AssignClientAuthority?
     
  9. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    I'm pretty sure there's no way to change authority all the time and have it be perfect. You are changing who is determining the position of the object and the object is literally in different positions on different screens because of latency. Smooth Sync smooths this out but there will always be jumps in position to catch up to the actual position when you change the owner of the object unless it is moving very slowly or not at all.

    Setting your InterpolationBackTime to negative numbers is probably not recommended for normal use because then it will try to extrapolate into the future all the time. Any changes in direction will probably look strange but it may be better than the alternative for you. You can try setting WhenToUpdateTransform to FixedUpdate() and your physics object may go through walls less when extrapolating though.

    Some ways to maybe make this less noticeable:
    Turn EasingSpeeds up to 1.
    Raise TimeCorrectionSpeed until you start seeing it jump around from being too reactive.

    What are you trying to accomplish with this Rpc? If it's solving "not changing position when you change who is controlling the position of the object", then nothing can be sent to solve this.
     
    Last edited: Mar 20, 2019
  10. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    4
    Thank you for you suggestions!
    I'll try them in future. But currently leaving the following:
    • Ball is always has server authority
    • All clients except host have variable size colliders (scale depends on ping and velocity of player)
    Without variable colliders rigidbody sometimes fly through remote players (visible on remote clients). But anyway - no glitches, not jumps, no lags. SmoothSync is awesome!

    Looks perfect either on one or several machines!

    Thank you for this solution! :)
     
  11. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @oleg_v
    Changing WhereToUpdate to FixedUpdate will make things go through colliders less if it has a rigidbody because it will then use rb.MovePosition(); to move the object around.

    I think putting InterpolationBackTime to positive so you aren't extrapolating all the time will help it not go through colliders too.

    Let me know if you have any other questions.
     
  12. oleg_v

    oleg_v

    Joined:
    Nov 10, 2017
    Posts:
    4
    Just tried: fixed colliders and WhereToUpdate = FixedUpdate for both players and rigidbody, "ball" going though remote player and the same behaviour for variable colliders. Therefore i'll leave WhereToUpdate = Update. Anyway, thank you!

    ps: Best solution is with default InterpolationBackTime = 0,1
     
  13. Velcer

    Velcer

    Joined:
    Mar 16, 2017
    Posts:
    13
    Will this work with DarkRift 2?
     
  14. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Astrovolts
    It will not work out of the box with DarkRift 2. I've had people convert to other networking systems without telling me they had too much trouble though, but I'm not sure I'd recommend it unless you are comfortable coding and know DarkRift well enough. I guarantee no ease of conversion but I do keep the code well commented. Feel free to ask any questions here if you run into any issues. If you don't know UNet at all, the PUN or PUN2 version might be easier to convert as it has more clearly defined sending and receiving sections where you just send and receive a byte array.
     
  15. MrHaribo

    MrHaribo

    Joined:
    Aug 9, 2012
    Posts:
    14
    Hello

    First of all, thanx for the great work on SmoothSync.

    Im Using it with Mirror networking. With the latest Asset Store version of Mirror im getting several deprecation warnings:
    • Warning CS0618 'NetworkClient.allClients' is obsolete: 'Use NetworkClient.singleton instead. There is always exactly one client.'
    • Warning CS0618 'NetworkClient.RegisterHandler(int, NetworkMessageDelegate)' is obsolete: 'Use RegisterHandler<T> instead'
    Will those be fixed in the near future?

    Also i am getting an error message in OnStartServer although im not sure the two issues are related.

    Do you have any advice on those issues?
     
    Last edited: Mar 21, 2019
  16. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @MrHaribo
    It looks like I'd need to rework the entire asset to get rid of those deprecation warnings. Extra classes I'd need to use all over the code under different conditions, methods. I really don't understand their reasoning for some of these changes. I'll look into it again later though and see how it goes.

    I don't get the OnStartServer error in the SmoothSyncMirrorExample scene. Do you have any tips on how to recreate the issue? It just happens when you start hosting on the server? Do you have the latest Mirror from the Asset Store? What Unity version are you on?
     
    Last edited: Mar 21, 2019
  17. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @MrHaribo
    Stick
    Code (CSharp):
    1. #pragma warning disable 0618
    At the top of SmoothSyncMirror.cs and it should hide the warnings for you for now at least.
     
  18. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @MrHaribo
    Actually, I couldn't get it out of my head so I just fixed the Mirror deprecation warnings. It ended up simpler than I was imagining too.

    I sent you a link to it in a PM.
     
  19. MrHaribo

    MrHaribo

    Joined:
    Aug 9, 2012
    Posts:
    14
    Hello again

    I checked back this thread and it seems that jacknero, Mar 8, 2019 had a similar error in the OnStartServer. I assume it might be the same problem, meaning it would be a Mirror related issue.

    Due to another problem (The breakpoint will not currently be hit. Unable to find corresponding location) i tried different Unity Versions 2018.3.7/8/9 in combination with Mirror Versions 1.1.0 and the latest Asset Store Version of Mirror. Due to this big mess of versions i cannot tell exactly in which combinations the OnStartServer issue occurs. Since my project takes a lot of time to switch the unity version it might require some effort to dig deeper. And yes, it only happens when i start hosting. But its difficult to track since i can't debug atm!!! *grrrr*

    But i have just seen that vis2k just released version 1.2.1 of Mirror and i will check if the issue still occurs. Unfortunately i am not working tomorrow so i will check this first thing on saturday.

    And finally, thanx alot for the fix of the deprecation warning. I will test it out right now:)

    Thanx for your fast reply and keep up the good work, it is well appreciated. Your packages rock hard:)

    UPDATE: Your fix of the deprecation warning seems to magically have solved the OnStartServer issue as well. I could not reproduce that anymore. Over 9000!
     
    Last edited: Mar 21, 2019
  20. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @MrHaribo
    Awesome! Glad to hear that cleared up the issue and thanks for bringing it to my attention. I'll PM them a copy and put out an update.
     
  21. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    I presently have a demo using my own hand-rolled networking atop Lidgren. Would I be able to easily swap in my own networking sub-layer in place of PUN/Mirror and the others provided within this asset? I do not wish to immediately decamp from my present networking basis, but I do want to benefit from your interpolation logic, etc

    tone
     
  22. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Tony-Lovell
    I probably wouldn't say you could do it easily, but as long as you know how to send a byte array over your networking, it shouldn't be too difficult. I do keep things pretty well commented though and I am always here if you need help. The PUN/PUN2 versions would probably be the easiest to convert as it's more general and there is a clearly defined sending and receiving section in OnPhotonSerialize().

    Let me know if you have any further questions.
     
  23. toyhunter

    toyhunter

    Joined:
    Mar 5, 2018
    Posts:
    34
    @Fuestrine

    I'm struggling into an issue might be all beginner faced. Wonder if SmoothSync already has solution for this...

    Background: Client vs Host / Client vs Client realtime game

    Situation:
    Player A pick up a box (SmoothSynced with Rigidbody) then throw it to Player B;
    Player A will execute the AddForce (with Cmd then Rpc);
    SmoothSync helps sync'ing the box the same motion, position;

    Issue: When the box hit Player B there is a bit of delay (few millisec) on Player A's screen, On Player B the hit is perfect timing though. Player A sees the box pass through Player B then after a few milliseconds Player B got hit.

    I keep researching how other games works on this but no result yet, please let me know if SmoothSync actually has a solution within, thanks.
     
  24. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @hmpublic2000
    Changing WhereToUpdate to FixedUpdate will make things go through colliders a bit less if it has a rigidbody because it will then use rb.MovePosition();

    Which player's system owns the box? Each player is owned by a separate client?
     
    Last edited: Mar 23, 2019
  25. toyhunter

    toyhunter

    Joined:
    Mar 5, 2018
    Posts:
    34
    @Fuestrine

    Player A owned the box when he picked up and holding it, box's SmoothSync will be turned off while being held;
    The above relationship will be reset once player A threw it out, and box's SmoothSync will be resumed

    Yes Each player owned by separate client
     
    Last edited: Mar 23, 2019
  26. toyhunter

    toyhunter

    Joined:
    Mar 5, 2018
    Posts:
    34
    I found a workaround:

    Server RPC all clients (seeing the box being thrown) execute the AddForce without SmoothSync, once the box (flying) hit any rigidbody or player, resume SmoothSync (LERP if necessary).

    Now it works like a charm :D
     
    Last edited: Mar 23, 2019
  27. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @hmpublic2000
    Does this box have a collider on it? If it has a rigidbody too, try setting WhereToUpdate to FixedUpdate

    If not, it sounds like maybe you are determining the hit on Player Bs side? So the box doesn't go away until Player B says they were hit by that box? The latency there would be then you have to tell Player A so it's going to be a bit behind. You could act like the box hit (but only visually like if it disappears normally) on Player As side when Player B gets hit maybe.

    EDIT: Sweet, sounds like you've got it solved, maybe the above is useful still though so I'll leave it.
     
    toyhunter likes this.
  28. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    Hmm, I hope I didn't hurt myself too badly from starting from the UNet side of things, whose overall gestalt was quite a bit unlike my own.

    So far, I have taken the following simplifying measures, as I do not see how I would apply them in my project:
    • ripped out NetworkID (as my code handles this)
    • removed support for child objects
    • removed change of ownership of objects
    • removed teleporting
    One quirk I find in the UNet version is that NetworkState seems to want to be combined with State.

    One odd observation: having time as a float invites worry that the code won't fair well on persistent games that run for a very long time. Might it be possible to add a "time reset" function once this time grows beyond a point where the measurable differences become large enough? I guress the code would riff through all the states and back-date the time marks.

    tone
     
  29. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    Ok .. quick question.

    I can send packets on my network in Unreliable as well as UnreliableSequenced manner. The latter, I suppose, will enforce they arrive in the order they are sent at the expense of possible resends, etc.

    Which is suitable for sending NetworkState?

    I already have Reliable messaging chosen for managing ownership, etc

    tone
     
  30. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Tony-Lovell
    Yeah, you could probably combine NetworkState and State. It just seemed easier back when I started with UNet and how it deserializes and serializes.

    That float precision thing is a good idea, thanks for letting me know about it. I'll probably use a float that gets added to with Time.deltaTime and then reset it when it starts reaching imprecision and hopefully handle it well on the other networking side too. It'll probably be about a week before I get the time to make and test this out fully though.

    Unreliable should be fine for sending the NetworkStates. It can automatically handle out of order States.
     
  31. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    I suppose one could just check for time to move backwards by a large amount, and automatically have the receiving end tickle all stored state-times by the tolerance delta.

    Due to my feature reduction and the fact that my network "platform" is really a roll-your-own, I don't think you will find my finished work very helpful, but I can supply some ideas for hooks that will allow it to deal with some nice bits that my game environment demands. The most valuable one is that I use a double-precision large world, but only ever pass single-precision positions across the net, relying on "origin resets" to insure that both sides agree on where the scene origin lies in the double-precision worldspace. It does it by sending a single additonal bit along with the position data. Adding this to the SmoothSync asset required only: reading and writing that single bit, a callback to permit the object being serialized to adjust position information (to deal with the case where the other side sent in the previous stage origin), and a function to tickle the stored state list in similar fashion to the time discussion above when the origin is reset.

    I will let you know how it looks after I get the entire thing working.

    tone
     
  32. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Tony-Lovell
    Alright, I've finished the Time.RealTimeSinceStartup float imprecision fix when running for a long time.

    I sent you a copy in an email. Since you are converting to your own system, use "diff folder1 folder2" on your command line to see the differences. "git diff folder1 folder2" if you have git will make it all colorful and easier to read. I'm probably going to wait a bit to release this as I'm a bit busy lately and I'm not trying to introduce any new errors while I finish up a different project. It all looks like no issues to me though. I don't notice time resetting back to 0 at all.

    If anyone else wants this fix, PM or email me with your invoice number if we haven't talked before and I'll send it your way.
     
    Last edited: Mar 29, 2019
  33. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    67
    I'm a new user of SmoothSync. I'm using it in place of Mirror's NetworkTransform because I need to share the Rigidbody state (velocity and angular velocity) so players can throw objects around.

    Works great when I'm just running on the host. However, when I have another player join in and I pick up an object on my end, they don't see the object move. I don't see any errors on my end, but on the remote player's machine they get a series of "Unknown message ID 46251" messages that start as soon as I take authority of the object on my end and stop as soon as I relinquish authority.

    Any thoughts or suggestions?
     
  34. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @BernieRoehl
    I'm not seeing this issue on my end. I did see that error though when I assigned client authority incorrectly while testing this. Double check that you have the right connection that you are assigning authority to, Mirror is a bit different than UNet. Your object should be "hasAuthority" on one of your game instances and my guess is that no connection has authority, which is when I was seeing that error.

    Here's how I assigned authority to the connected client when I had just one host and one client:
    Code (CSharp):
    1. foreach (var kv in NetworkServer.connections)
    2. {
    3.     NetworkConnection conn = kv.Value;
    4.     if (conn != NetworkServer.localConnection)
    5.     {
    6.         //non local client's connection
    7.         networkIdentity.AssignClientAuthority(conn);
    8.     }
    9. }
    Let me know how it goes or if you think that's not the issue.
     
  35. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    67
    I suspect that's not the issue.

    After a good night's sleep, it occurred to me that it probably has nothing to do with assigning authority. When I pick up an object, it gets re-parented to the player's hand (I'm using SteamVR's Interaction System). So if SmoothSync is sending *local* position and rotation, but I haven't reparented on the remote client (only on the local one) that would explain what I'm seeing.

    Although I'm not sure where the unknown message ID messages are coming from.
     
    Last edited: Mar 30, 2019
  36. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @BernieRoehl
    I'm not seeing the Unknown Message ID messages when I change the parent of an object either. I'm also not seeing it when I change the parent then change the authority. Let me know if you are able to narrow down how to recreate the issue so that I can recreate it on my end.

    Alternatively, you can send me your project in a PM or an email with steps on how to replicate the issue. Preferably in a way I can replicate it without using a VR headset.
     
    Last edited: Mar 30, 2019
  37. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Paradoks
    Hey, I was told you were having teleport issues.

    I don't see any issues with teleporting in the SmoothSyncMirrorExample scene. I set it up according to your SmoothSync settings and press "t" to teleport. Take a look at the example scene and SmoothSyncMirrorExamplePlayerController.cs to check if you are doing anything different. You said you were using teleport(), I've added new teleport methods since you started using SmoothSync, but it is also set up in the background to use teleport() in the same way as always so I don't see how that could be the issue.

    If you are doing things the same way as the example scene, let me know. Though I'm not sure what could be going wrong otherwise.
     
    Last edited: Mar 31, 2019
  38. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    422
    Hello, i just saw that the Teleport() was deprecated.
    Wich one should i use instead ?
    Will it make any difference?
    Could you check the behavior by yourself in my game:
    http://www.adversator.com/
    click shop button lower right, then go "Spell items" and buy the "Blinker" object.
    Then try to TP, you will see the result.
     
  39. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Paradoks
    It's deprecated but it's still used like the old one, I just renamed it to teleportOwnedObjectFromOwner() and teleport() calls this method. I added teleportAnyObjectFromServer() and figured the other method needed to be named more appropriately to teleportOwnedObjectFromOwner(). TeleportOwnedObjectFromOwner() is probably what you want to use if you are calling it from the owner. TeleportAnyObjectFromServer() is probably what you want to use if you are calling it from the server.

    I took a look at your teleport behavior. I'm not really sure what could be causing that. Is the player server owned and I am the non-owner client if I'm the only one in the game?
    It looks like you might be setting the position of a non owned object to do your teleporting as well as telling the server owner to teleport. This could cause it to go back to where it was because the server hasn't gotten the teleport message yet then the teleport from the server tells it to teleport and you may see your back and forth that you are seeing. To solve this, don't set the position locally, only set the position on your owner. Take a look at the example scene for a more detailed and exact scenario for teleporting.
     
    Last edited: Mar 31, 2019
  40. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    422
    the game is full authoritative, the teleportation is made server side only, i installed the latest SmoothSync version and took a look to the example scene, i do the same thing.
    I keep investigating.
     
  41. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Paradoks
    I'm not sure what could be going wrong if you are doing what the example does when it teleports.
    Does the example scene have the same issue when you press "t" to teleport?
     
  42. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    Can you sanity check my thinking here? My game has a very large world, and the server occasionally commands a "scene reset" to telling a client ship who has strayed beyond a certain comfort zone near his scene origin to move himself and everything backwards by the local owned ship's scene position such that all relative relationships in position are maintained, and the local owned ship is at scene origin. I have tried to tweak SmoothSync so that it can manage these scene resets, but I have either introduced a bug or do not understand what I must do to keep SmoothSync properly informed.

    Here is code that gets run on each SmoothSync item when the local scene is reset.

    Code (csharp):
    1.  
    2.         // this is added on SmoothSync, and is called after I move the GameObject's position by -originShiftedBy
    3.         public void onOriginShift(Vector3 originShiftedBy)
    4.         {
    5.             // reach into the stateBuffer and adjust the positions of each as required
    6.             for (int i = 0; i < stateCount; i++) {
    7.                 stateBuffer[i].position -= originShiftedBy; // origin movement is opposite of object position
    8.             }
    9.         }
    10.  
    However, this does not appear to work: I see in debugging displays that my client's ship moves near the origin, but then it leaps ahead, I think to its old place or somewhere similar. Have I missed something?

    N.B.: I do not use any of SmoothSync's features for managing changes in Authority (this never really happens in my game) or Teleporting (also never happens, except this perhaps resembles it).
     
    Last edited: Apr 1, 2019
  43. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Tony-Lovell
    It looks like your solution should work. One issue could be that a State is being sent over the network from the old position that gets added after you do this. Maybe check in addState() to see if you are receiving an old position after you change all the positions in the stateBuffer. Other than that, I can't really think of what would be setting the position besides the States that get received and added in the stateBuffer.

    This may be a good time to implement the teleportation though. Take a look at teleportOwnedObjectFromOwner() and teleportAnyObjectFromServer(). They should be easy to implement as they are basically just normal RPCs that add a State so that non-owners know not to ease between transforms.

    Let me know how it goes.
     
  44. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    I think my bug lies outside my transmogrified version of your code. I do already have some pretty good handling of positions being sent in the previously-commanded origin space... both sides can back those out when they occur.

    I should get this... eventually.

    Tony
     
  45. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    119
    @Fuestrine We are working to sync physics over the network with two players hitting a ball and trying to score it in opposing goals. It is server authoritative. The effect we are trying to achieve and sync over the network is similar to Rocket League: https://plays.tv/embeds/593824f2d190905bea

    I was wondering if SmoothSync could be used to achieve something like this? And if so, how would you do it? I've been struggling to get it working.
     
    Last edited: Apr 2, 2019
  46. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    I'm getting fair results in many ways, but one part where I see very little smoothing occurring is the angular behavior of my ship on the ocean. That is, my ships are presently rolling in fits as the direction of roll is reversing, and fairly well in the middle of the roll where the roll rate is fairly constant.

    My code is set up this way:
    1. The server physically models the hydro forces of the ship on the ocean waves. The Rigidbodies on the client ships are set to isKinematic=true
    2. The clients are sailors on the ship who need to see it move continuously in angle and position
    3. My settings are shown below. I am trying to establish settings that take advantage of the fact that the ships move fairly predictably and smoothly. I'd like the lowest send-rate possible that gives the sailors the impression that their ship is moving smoothly in all rotations.
    4. Screen Shot 2019-04-02 at 7.59.15 AM.png
    Some questions I have are:
    1. I do not understand what it means to sync Rigidbodies ... what do you do with these on non-owned ghost objects? Do you destroy them, disable them, set them kinematic?
    2. What does syncing RBs do that you do not get from synching the position and rotation on the GameObject containing these RBs?
    Some ideas for enhancements:
    1. "Interpolation Back Time" would perhaps be more elegantly expressed not as a measure of time, but as a multiple of "Send Rate". Or vice-versa?
    2. It might be nice to be able to tell the SmoothSync layer what your ping time is, and have this knowledge propagate through the network to adjust send rates and interpolation back times.
    3. Having the option to have the network packets contain bit masks expressing which variables being sent are compressed, and which are not, might help game like mine, which could choose to compress data for objects that are far away from the recipient.
    4. Similarly, including an optional hook function (e.g., float sendRate(SmoothSync sender, Object recipient)) could allow a user's server choose to throttle back on send rates between players that are not very close to each other. This variable sendRate concept would also benefit if bullet #1 were implemented, as InterpolationBackTime would be automatically sane, as it would remain proportional. The server could simply tell each client the sendRate it should use to suit the recipient object with the highest demand for receiveRate, and meter the less needy nodes accordingly.
    Tony
     
  47. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
     
  48. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @TCROC
    Basically, no. A game like rocket league has everything owned by the server and custom player / client prediction to make everything react instantly on local but still have it's position determined by the server. You may be able to turn Smooth Sync into a custom player / client prediction solution but it would be very difficult.

    One way to achieve this might be to pause a bit on hits and send over AddForce rpcs to hit the ball but it won't instantly react.
     
  49. Tony-Lovell

    Tony-Lovell

    Joined:
    Jul 14, 2014
    Posts:
    93
    One thing I think my code above misses is adjusting SmoothSync.targetTempState's position.

    I am still testing the overall fix. It may be working now.

    tone
     
  50. Fuestrine

    Fuestrine

    Joined:
    Feb 13, 2013
    Posts:
    429
    @Tony-Lovell
    Hmm, I'm not sure what could be going wrong with rotation. I never really tested rotatable objects large enough to fit players on it though so I'll take a look tonight and make sure my rotation math is accurate. Your settings look pretty good, I don't believe they are causing any issues.

    Ghost objects? I didn't want to mess with anything on non-owned objects since people may change ownership, so I set the velocity to 0 on non owners with a rigidbody component so it doesn't try to change position from the easing positions.

    I think you are referring to my "Network your rigidbodies and transforms" line? I definitely worded that wrong. It's all just syncing game objects and game objects that have rigidbodies. It should probably say "sync transforms, including those with a rigidbody".

    All pretty good ideas for enhancements, I'll add them to my list. I don't plan on implementing any anytime soon though as I'm trying to keep things stable as I finish up some other projects.