Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How much "non-deterministic" Rigidbody physics are? (plus if Character Controller is better)

Discussion in 'Physics' started by DimitriX89, Mar 23, 2021.

  1. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    I keep hearing that Unity physics system is non-determenistic, and sometimes that it isnt. What that means from a practical standpoint? The results of physical simulation will be different between different machines? If I'd, for example, created the recording of player inputs over time, would they play back consistently on Rigidbody based controller?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    Non-determinism here is mostly caused by the differences in floating-point arithmetic implementations on different devices/platforms and not by Unity itself or the physics systems integrated within it therefore non-determinism affects ALL of Unity but it's seen most commonly in physics simulations where a minor difference in a floating-point value (such as a position/rotation/force etc) accumulates over time to produce a larger and visible difference which is the same as chaos where a tiny change in initial conditions can results in large unpredictable state changes later.

    You can see this by doing some complex math operations on different devices over a period of time then showing the results; there will be differences for the same algorithm.

    There are many strategies to counter this in various networking models for instance such as being strategic on who has authority on position/rotation and/or adding in sync-points etc. This is not my expertese but the main point is that you cannot rely on floating-point results being identical across different devices. Obviously identical devices should be fine and certainly on the same device.
     
    DimitriX89 likes this.
  3. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Thank you, so it is mostly problem between different devices. But how would one go with making 100%- desync proof system in 3d (like Doom 1 and 2 demo playback)? Sure, internal calculations can be done all in integers, but to apply result to Transform or Rigibdody, they'll need to be converted to floats, right?
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,316
    As I said, I am not an expert in this field but there's also lot of information online about this kind of stuff. Maybe someone else will jump in and give you some pointers too.
     
  5. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    I've read some articles on the topic, and seems it is not something to undertake on a whim. Amount of custom coding required will likely kill all benefit of using Unity. Adding a single feature like demo playback won't be worth such trouble.
     
  6. DimitriX89

    DimitriX89

    Joined:
    Jun 3, 2015
    Posts:
    551
    Another thought on the topic, what about the Character Controller component? Will it have the same playback differences between different machines as Rigidbody based controller? I saw posts calling it "more deterministic", while it uses floats as well, right?
     
  7. xdarned

    xdarned

    Joined:
    Apr 11, 2022
    Posts:
    2
    I have an example on the same structure having different physics solutions in the same scene in the editor:

    One object is a copy of the orher. The original structure has hinge and fixed joints. Large amount of mass is being applied to the side and rear of the object.
    You can see that both structures, despites being the same, behave differently.
     
    DimitriX89 likes this.
  8. ireakhavok

    ireakhavok

    Joined:
    Feb 9, 2023
    Posts:
    19
    yeah, so, unity does not have deterministic collisions. This causes small discrepancies in position. I wrote code that basically performs the exact same calculation on both client and server, and compares the position of the player. During freefall, the player is deterministic, however on landing the collisions, I assume cause the client to become out of sync with the server.