Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Networking with Unity Physics

Discussion in 'Physics Previews' started by MrHaribo, Jun 3, 2019.

  1. MrHaribo

    MrHaribo

    Joined:
    Aug 9, 2012
    Posts:
    16
    Hello

    I am working on a physics based network asteroids game. Since its competitive, local physics authority is not an option so an authoritative server is required. Yet i did not have any success implementing a working rewind and replay solution with Unity's built in PhysX system.

    The blog post about the new Unity Physics states, that it's stateless nature allows it to realize physics rollbacks. But are there already any examples that showcase this?

    And how does non player input can be modeled in such a environment? For example when an asteroid is hit by a player, what kind of input must be buffered for the asteroid?

    As far as i understand physic engines, every step during the broad and narrow phase, collision pairs are built and afterwards all contacts are solved by applying impulses. But when physics are replayed, only a single body is simulated and therefore all other bodies are in a wrong position relative to the simulated objects timeline. I cant get my head around this problem.

    Im not sure if this is the right place for these questions but any help would be highly appreaciated. It also has to be said, that my game is still in a prototype phase so switching out physics technologies is still a option for me. But using the new Unity Physics seems very exciting and it would be awsome to solve my problems with this new technology.

    Thanx for any advice.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Authorative server, doesn't mean it processes only inputs.
    It has whole game simulation, which is only true.
    It receives inputs, and sends syncing data, to ensure, players and objects are in right transformation.
    Also, it sends all required game states.

    So that solves your asteroids problem.

    Other then that, you are looking for determinism.
    You can achieve that to certain extent already on physX, along with fixed physics simulation time.
    But I am also looking forward to new physics system. But a bit too early for me, other than running some trials.
     
  3. MrHaribo

    MrHaribo

    Joined:
    Aug 9, 2012
    Posts:
    16
    Thanx for youor reply

    What you say is all true, but in my case, since asteroids are moving objects, misspredictions on the client are inevident. My question is, how can i rewind the state (position, velocity) for a body and reapply the buffered inputs until the most recent frame.

    I based my implementation on Overwatch Command Frames (i got that working more or less):


    I use the prediction reconciliation code from here:
    http://www.codersblock.org/blog/client-side-prediction-in-unity-2018

    And finally i plan to use the Rocket League Prediction Approach:


    At the moment i am trying to resimulate all bodies from the last received authoritative server state until the current client frame. This means i have to rollback the entire physics simulation on the client and replay it for approximately RTT/2/dt ~ 4-7 frames. This is quite cpu intense. For the replay i am using Physics.Simulate

    It would be a lot better to rollback only the bodies that were misspredicted. Is there any solution for this?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,776
    Look into Unity fps sample. There is network technical video, which explains, how they did syncing and dealing with past/future time, between server/client.
     
    Last edited: Jun 4, 2019
  5. MrHaribo

    MrHaribo

    Joined:
    Aug 9, 2012
    Posts:
    16
    Thanks for the advice

    I will look into it...