Search Unity

Multiple players following one object

Discussion in 'Multiplayer' started by WaitYes, Feb 16, 2018.

  1. WaitYes

    WaitYes

    Joined:
    Sep 5, 2016
    Posts:
    11
    I'm making a game where the players each take a different position to crew a spaceship. One's the captain, another's the gunner, another is the engineer, etc. It's in the same genre as Artemis or Star Trek Bridge Crew. The difficulty that I am having is that each player needs to have cameras that follow the ship. But because the ship is either on the server or on the client of the pilot, the movement of the camera on all the other clients is jittery. Every tenth of a second, as it gets an update, it jolts over to the new position. How do I fix that?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You need to interpolate between these position updates rather than snapping to them.
     
  3. WaitYes

    WaitYes

    Joined:
    Sep 5, 2016
    Posts:
    11
    The problem with just using interpolation is that the new position will be often be more than 1/10th of a second behind. After more research, I realized what I really need is to do some client-side prediction. This is difficult in Unity's physics environment. Anybody know how to do client-side prediction with Unity's physics?
     
  4. ItsaMeTuni

    ItsaMeTuni

    Joined:
    Jan 19, 2015
    Posts:
    44
    You can read this. It doesn't give code examples, but it shows you what the script should do. The prediction shouldn't be too hard... Store in a variable the last position of the ship, calculate the difference of the last position and the current position, interpolate to the current position + the difference until you get another update from the server.

    For example:
    You receive the position of the ship at t=0.1s (let's call it pos #1). Then a tenth of a second later you get position #2 at t=0.2s. To solve the jittering you store #1 in a variable (lets call it lastUpdatePos) when it arrives, when you get update #2 you calculate the difference in position #2 - #1 and store that in a variable (call it posDiff). Now you're going to to predict pos #3, to do that you do #2 + posDiff and store it in a variable (call it predictedPos). Now just interpolate to that position and when update #3 arrives calculate it all again.
     
  5. WaitYes

    WaitYes

    Joined:
    Sep 5, 2016
    Posts:
    11
    I already found the Gabriella Gambetta article, and it is pretty great. And thanks for the advice. I'm pursuing a bunch of options and I'll try to post again when I figure something out.
     
    ItsaMeTuni likes this.