Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unable to get deterministic physics

Discussion in 'General Discussion' started by neeravblacklight, Jan 14, 2019.

  1. neeravblacklight

    neeravblacklight

    Joined:
    Apr 13, 2018
    Posts:
    4
    Hey,

    I've been developing multiplayer carrom/billiards and i'm unable to get determinism in unity's physics.

    Configurations:
    1. Physics auto simulation is off and is managed from the from the update method.
    2. All the coins/cues are using capsule/sphere mesh
    3. Inputs are:
    a. power
    b. direction
    of the striker to be fired

    I'm able to get the same simulation when running on the same device.

    Issue occurs when Device A send input to Device B, there is a difference in final state of the board after all the collisions and movements are done. This issues varies with the specification difference among the two devices.

    I've read that unity manages the lag part in the physics due to x reason and makes up for it when the lag goes down. But still i'm not able to get proper determinism in physics.

    I'm not sure where i'm going wrong. I'm sending a final sync state to get both the devices on the same state as a word-around to cope with this issue. But the force sync after everything stops moving looks very weird.

    Any help would be much appreciated, thanks.

    Ps: we've to send minimal data to the server.
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Unity's current implementation of physics is by design non-deterministic.
     
  3. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,575
    As in most games, even most deterministic, there are still sent states for syncing.
    Hence, some form of syncing would be required.

    Since is a billiard, lag shouldn't be an issue.
    And amount of data sent to server / clients, is rather puny, compare to RPG, RTS, FPS online games.
    Hence I wouldn't be worry too much about it.
     
    neeravblacklight and xVergilx like this.
  4. neeravblacklight

    neeravblacklight

    Joined:
    Apr 13, 2018
    Posts:
    4
    oh, i've been at it for some time now. Thanks
     
  5. neeravblacklight

    neeravblacklight

    Joined:
    Apr 13, 2018
    Posts:
    4
    ok, when you compare it to RPG, RTS, FPS it will be much less. But still is there any way on to sync the game state without letting the user realise something moved after the game cue's settle?

    Event flow is as follows:
    - User A fires, and sends fire data to User B.
    - User B on getting the data fire itself.
    - Somewhere between the cue movement of B, A reaches final state and sends to B
    - B then assigns destinations to the cues that it got from A whiles it's(B's) cues are still moving.

    This works, but sometimes the state sync is visible. One can see the cues moving backward or forward or even coming out of the pockets.
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,575
    You can relatively easily precalculate future states, hence you can send information about, where next position should be at given time. As result, you will have guaranteed states on either client.
     
    Joe-Censored and angrypenguin like this.
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,509
    Yeah, due to the simple physics required in this case, I would calculate the end result of the shot as soon as the fire input is given, and then have both computers play an animation which reaches that state.

    I probably wouldn't use the built-in physics system at all (maybe aside from collision detection?), for two reasons. First, it'd likely be more effort to figure out what inputs to the physics system will give the results you need. Second, the built-in phsyics system is pretty general purpose and doesn't to stuff that I'd expect a detailed Billiards simulation to cover, such as the cloth surface having different friction in different directions.
     
    Antypodish likes this.
  8. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,960
    Unity is so advanced the quantum physics are kicking in, which adds a bit of randomness
     
    Braineeee, xVergilx and hippocoder like this.
  9. proepkess

    proepkess

    Joined:
    Dec 26, 2016
    Posts:
    11
    Antypodish likes this.