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.

Netcode - NetworkTransform Interpolation for Orbit

Discussion in 'Multiplayer' started by dalinut, Feb 28, 2023.

  1. dalinut

    dalinut

    Joined:
    Aug 31, 2017
    Posts:
    3
    Hi,
    I am updating my Unity game project from the old UNet to Netcode. I have a (2D) ship object that is updated by the server (and using a NetworkTransform its position/rotation is sync'd with the clients). This works well when the ship is moving in a straight line, or even turning, but in the past when I was using UNet, when the ship went into a circular orbit around a planet (the interpolation) didn't work very well. I ended up having to not use a network transform (I forget the specific UNet details as it was a long time ago) and having the client update the Ship's position locally.

    Before I implement the orbit in the Netcode (to see what it looks like) - do you think that the interpolation will "just work" for this type of orbit (Note, the ship is about 1 inch and the planet is about 4 inches in size - so the orbit is quite "tight"). If the interpolation doesn't work, is there a way to turn off the NetworkTransform control of the ship's position (while it is in orbit) so that the client can handle calculating a smooth circle around the planet?

    Any input is appreciated.

    Thanks, Dalin
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    2,415
    Since you are updating your project anyway (if I understand correctly), just give it a try. You'll see for yourself how it behaves anyway. ;)

    Whether it looks okay really only depends on whether the interpolation simply tries to predict a straight-line movement only, or whether it looks at historical changes in position (= circular movement) and keeps applying that.

    Either way, client-side prediction will look best in any case, and I doubt that even clever prediction will make it go around the orbit in a smooth way. If the orbit is even a "mode" that the ship enters or leaves on user command only, then it would even make sense to only record the enter/exit orbit mode state and in-between have the client predict the ship's orbital position provided that the movement is deterministic.
     
  3. dalinut

    dalinut

    Joined:
    Aug 31, 2017
    Posts:
    3
    Hi, thanks for the input. I agree that the client handling the "smooth" orbit looks best - and this is how I implemented it originally. However, I'd like to use the Network Transform so the client doesn't have to do the extra work. Regardless, if I decide to have the client handle the orbit, I somehow need to turn off the NetworkTransform... do you know if this is possible. Ie, (as you note) the server sends a client the "go into orbit" command, so if I can turn off the client's "listening" to the server's Ship position and have the client take over at that point (until the "leave orbit command") - this could work. I just don't know how to approach this (yet). My first thought is to grab the NetworkTransform component and deactivate it - but I don't know if I can do this. Again, any comments are appreciated. Thanks, Dalin