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

What to pass into physics.simulate for 1:1 parity with Update?

Discussion in '2017.1 Beta' started by hippocoder, Jun 9, 2017.

  1. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    https://docs.unity3d.com/2017.1/Documentation/ScriptReference/Physics.Simulate.html

    I'm doing arcade physics and I'd like my physics in sync, so what is the ideal simulate time? your documentation clearly advises against passing a variable delta, so I can't.

    I don't want my update and fixed update out of sync...
     
    Peter77 likes this.
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Passing a variable timestep means you can't count on your simulations to be deterministic or super stable. But that's not necessarily the end of the world. It would be bad for games where there's a lot of "physics contraptions" such as KSP or Besiege, but in arcade-type game it would be fine.

    Physics in UE4 are synced with framerate by default, presumably because it's great for fast games with tight controls like Unreal Tournament. Just be sure you give your simulation a maximum allowed timestep so that it can re-call the simulation several times in case there's a huge framerate spike. That way, you won't have physics objects doing any crazy stuff.

    Here's an excellent read on the pros and cons of fixed/variable timesteps: http://gafferongames.com/game-physics/fix-your-timestep/
    The "Semi-fixed timestep" part is what I'm suggesting here. I highly suggest you read the whole thing. In fact, this entire blog is a gold mine for physics and networking

    And finally, here's an explanation of how UE4 handles its variable timestep: http://www.aclockworkberry.com/unreal-engine-substepping/

    _________________

    P.S.: Another (sketchier) option that almost never gets mentioned is to keep a fixed timestep, but always make it go at a higher rate than your maximum possible rendering framerate (75hz or 144hz for example). That way, you get all the stability of fixed timestep, with all the responsiveness of variable timestep. It'll cost you in performance, but it might be an interesting option if you have a lightweight game and you want to use that opportunity to give it 'flawless' physics response. You could add an option in the menus where the users can choose their framerate cap, and that sets both the rendering framerate cap and the physics rate to that. But it doesn't prevent users from shooting themselves in the foot by setting ridiculous framerate caps that make their game run slower than it normally could.
     
    Last edited: Jun 10, 2017
    landon912, mh114 and MelvMay like this.
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thanks a lot for the tips :)
     
  4. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Alternatively, if you want to do exactly what Unity does internally, Melv's post here does the trick. No max frame time implemented there though! Either way, the links Phil have posted are generally a goldmine.
     
  5. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,579
    www.gafferongames.com is an awesome resource. Thanks for sharing!