- Home /
Deterministic physics, same platform
I'm aware that unity physics aren't deterministic on different platforms, but what about a consistent platform like IOS? When answering this question, please can you confirm whether this applies to the latest Unity engine (3 at this point) or whether it is information gleaned from older posts.
Answer by taoa · Feb 08, 2011 at 02:36 PM
I would be very wary of basing my project/application on the assumption that physics are deterministic, even on a given platform. For if it eventually reveals to be untrue, if you believe 'some guy on the internetz who told you it was', you'll end up with a massive problem on your hands.
In your situation, I'd assume that it isn't and build your project on this decision.
Plus, in physics engines, there's no telling when one person's machine might do a little error and end up being out-of-sync after a check.
I can provide proof that physics are not deterministic even in the same platform. In the scene I have a copy of a structure using hinge and fixed joints. Both structures have the exact same configuration, though both of them behave very different to each other when running the simulation.
https://www.youtube.com/watch?v=xV0gUL1qxJ4&ab_channel=StanKeyal
Answer by Bunny83 · Feb 08, 2011 at 04:37 PM
Beside the hardware limitations like floating point precision that will accumulate over time there are some things, even in the "real" world, that can't be calculated/determined.
Best example the double pendulum.
double pendulum is incredibly fascinating! That said, my constraints are simpler, it really is just unpivotted collisions, but I can't see how I'll ever avoid needing to keep things synced.
Answer by Ashkan_gc · Nov 11, 2013 at 12:08 PM
Unity physics is not deterministic even in the same machine. You can disable coan friction and do some other tricks to make it more deterministic but at the end it's not at all.
We tried to make a replay based on physX but could not because of this fact.
Answer by teslatron · Oct 31, 2014 at 02:18 PM
We made Unity physics deterministic between Windows running PCs'. It was not deterministic even on the same machine at first but after making tremendous tests we finally made a setup that is almost deterministic. I say almost because we still not able to make it cross-platform deterministic. But I may say it is fully deterministic between PC-Windows machines.
Our findings to achieve windows platform determinism:
Magical Settings:
Rigidbody.useConeFriction = false
Make extreme caution to not to overlap or pass-through colliders in the scene. Only physics engine should handle collisions and transform operations.
For all rigidbody objects in the scene:
Rigidbody Collision detection = Discrete
Rigidbody Interpolate = None
And when moving physics objects by code, we came up with this, make sure it is called in FixedUpdate():
IEnumerator SyncCallback()
{
if (rigidbody.isKinematic == false)
{
rigidbody.velocity = Vector3.zero;
rigidbody.angularVelocity = Vector3.zero;
}
rigidbody.isKinematic = true;
yield return new WaitForFixedUpdate();
rigidbody.position = mSyncData.Position;
rigidbody.rotation = mSyncData.Rotation;
yield return new WaitForFixedUpdate();
State = mSyncData.State;
rigidbody.isKinematic = false;
}
SyncData is basically:
public Vector3 Position { get; set; }
public Quaternion Rotation { get; set; }
Hi teslatron, Can you explain how this cod works?, I see this make rigidBody kinematic for a short time so you can change its position and rotation by code, then after a short time rigidBody isnt kinematic anymore. How do you get that input data, mSyncData.Position, mSyncData.Rotation?, and what does this line means: State = mSyncData.State; ?, Im trying to do a GunBound Style game on mobile BTW. Regards
Answer by jpthek9 · May 09, 2015 at 12:24 AM
Yes! But not by default. Here's my implementation that will be on the Asset Store: http://redd.it/358hl6.