Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Movement is really skippy on multiplayer

Discussion in 'Multiplayer' started by FoxCastz, Dec 14, 2015.

  1. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    So, when played offline the movement is all super clean and smooth, but once I added the network tools; network manager and network identity, it breaks. The movement goes from smooth, carrying velocity to sudden random stops every second. Is there a problem with adding force to a rigidbody in a multiplayer game?

    Edit: And when a second player connects, their object has crazy spasms.
     
    Last edited: Dec 14, 2015
  2. GixG17

    GixG17

    Joined:
    Aug 18, 2013
    Posts:
    105
    The spasms might be caused if every client attempts to compute their own physics for each GameObject at the same time as the server.

    Have the server be the only one to calculate physics and, as for player objects, make sure only the client that has authority on the GameObject compute movement for that specific object. If you spawned that GameObject with NetworkServer.SpawnWithClientAuthority(), then everything should work.
     
  3. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Ok, I understand the point your trying to make, but how do I make the client stop computing physics? Would I have the
    Client RPC every input to the Server? The process is a bit confusing and I also had to use photon because for some reason the android os freaks out with unet. I could set up a screenshot of what the freakout looks like if your willing to explain why it does it. :) thank you for helping
     
  4. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    AFAIK, clients who don't have authority on game objects might do some physics updates at the client level (through interpolation, until the next updates from the server at which point they will reconcialite their local changes with the server's state) but won't send these to the server.

    The only scenario I've encountered with jumps actually due to synchronization is when the server was trying to reset the position of a local player object with the authority at the level of the client (so the client was correcting back its position directly afterwards). And I think the issue only occured on the server+client application (so, the host), so it could be that it was not the server that was "wrong", but the client part that was being synchronized.

    How is your NetworkTransform setup? What's the refresh rate? What interpolation settings do you use?

    In all my tests (though there's not been a lot of them), the rigidbody&force-based controls always gave the best results in term of synchronization and non-stuttering.
     
  5. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    I've messed with the different sync rates and it does nothing for it. I am still trying to understand how to fix what you guys are saying about the server and clients fighting over a position.
     
  6. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    It all depends who has "authority" on the object. By default, the server has authority on everything so the position is always synchronized from the server to the clients.

    But, usually, you'll give to the clients the authority over their respective player object, so they'll be able to modify themselves its position, which will be synchronized back to the server and propagated to the other clients. Naturally, a client only modify the position of its own local player (the only one on which it has authority), but not the objects that represent the other players (which get synchronized from the server).

    When this "who does what" is managed, the NetworkTransform customisation kicks in to see exactly how this information gets synchronized back to the server and to the other clients. But I'm still learning there, so there are quite a few elements I don't really grasp yet (by example, is the synchronization of a game object - which authority belongs to a client - from the client to the server handled through the NetworkTransform or is it another mechanism? And if it's using the NetworkTransform, does this mean that the synchronization from such a player object has to go through two NetworkTransform-based synchronization, one from the owning client to the server and one from the server to the other clients? If not, how often is the transform of the player object synchronized with the server? And so on)
     
  7. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Ok, so I remember seeing something like local player authority and server only checkboxes, but that was with UNET. I had to start using Photon because of another glitch prior to this one. Below I will post a picture of the issue I was(and still am) having with both unet and pun. The screen is all jacked up as soon as it enters a scene with networking involved. The only reason I used Photon instead is because It doesn't require me to click things to join a match, I can just code it in. When it connected to a match the screen would fix itself and progress to the issue at hand.

    Edit: Solved by adding a camera to the scene.
     
    Last edited: Dec 16, 2015
  8. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    Sorry, I don't know Photon...

    But AFAIK, you could also very well write a piece of code to directly join a server in Unity, instead of using the NetworkManagerHUD? I don't know the API by heart, though, but I remember some samples about that in Unity's manual.
     
  9. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    is afaik just another connection tool?
     
  10. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
  11. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Ooh may try that next tomorrow :) I will post any issues I run into tomorrow on here.
     
  12. jathrek

    jathrek

    Joined:
    Jul 16, 2015
    Posts:
    36
    Well, if you're already quite ahead in your Photon implementation, I don't know if it's worth changing now.
     
  13. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    Ok so in trying to implement the manual connections, theres still the issue of that picture I posted above. As soon as I enter the multiplayer scene the phone glitches like that, but is waiting for an input.
     
  14. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    This is an issue I have run into while converting my single player movement controls to multiplayer. The controls used to all be a smooth movement blend that would carry momentum, but now it is continually stopping. This video is to show people what I am talking about.
     
  15. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Did you have SyncVars constantly updating your speed variables? Or do you have a global variable where both the server and the client are checking it constantly?

    I seemed to have this issue with my multiplayer game, where both the server and the clients are checking at multiple units' current health points and max health points, and somehow, ended up multiplying the values more than intended when said multiple units are "upgraded". I'm looking for alternative approaches at the moment, and if you know a few, let me know.
     
  16. FoxCastz

    FoxCastz

    Joined:
    Jun 18, 2015
    Posts:
    75
    So, I found the issues source! I had a max speed setup for different objects and I didn't sync them to the server, thus resulting in the velocity continually being set to 0 at certain intervals. Thank you for the help guys!