Search Unity

Client Side Prediction - PhysX Resimulation Hack

Discussion in 'Multiplayer' started by nocanwin, Apr 21, 2016.

  1. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    Not sure what the gotchas are yet, but I figured out a way to make FixedUpdate run x number of times between Updates. Useful for fast forwarding the simulation or client side prediction. Just call this first part:

    int count = 0;
    int resimFrames = 456;//number of frames you want to resimulate or fast forward
    Time.captureFramerate = 1;
    Time.timeScale = resimFrames / (1f / Time.fixedDeltaTime);
    WaitForFixedUpdate wait = new WaitForFixedUpdate();

    while(count < resimFrames)
    {
    count++;
    yield return wait;
    }

    Time.captureFramerate = 0;
    Time.timeScale = 1;

    It'd be nice if unity let us step physics manually, but maybe this will work in the meantime. I've got it working in a basic scene doing some client side prediction and it seems to work pretty good. :D
     
    Last edited: Oct 18, 2016
  2. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    433
    Hi, I'm stuck in here, is that any artifact comes with this hack?

    BTW there're some rumors said resimulation will comes true in 2016, and PhysX will be upgrade to the latest version in 5.5, I'm not sure will resimulation comes at that time though.
     
  3. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    Not that I'm aware of but you'd have to tell everything to stop while you resimulate. Depending on your game this could be a huge PITA

    The collisions in my game are just sphere/sphere so so I ended up not using this method and writing my own collision code. Hopefully Unity adds resimulation.
     
    Last edited: Oct 18, 2016
  4. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Hi @nocanwin Can you provide an actual script that you made this happen with. I'd like to see what you did.
     
  5. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    Sorry, I'm not sure what you're asking for @DRRosen3. I've adjusted the initial code so you can throw it into a coroutine and it should work. If you're asking how I would use it for client side prediction then that is a much more complex issue. Running the resimulation is only a small part of it. Again, I ended up not using the hack so I'm not sure what all the pitfalls are.
     
  6. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Oh so this isn't actually a working concept (yet)?
     
  7. nocanwin

    nocanwin

    Joined:
    May 7, 2009
    Posts:
    176
    I'm not sure what you mean? Concept for what? The code is dead simple and it works.