Physics and Determinism

This is a really interesting topic for me so I tinkered around and discovered that apparently PhysX is deterministic to some degree. I didn’t find a lot of docs from nvidia discussing it but they do say that essentially if you guarantee the inputs, order and timing that it will produce the same output repeatedly.

And, in my tests this seems to be accurate, at least within the parameters of my test.

In the video you’ll see the Avatar entities moving around based on WASD inputs. A Simulation Layer subscribes to Unity Update Ticks and based on your timing requests it will use the delta time to run the simulation at a specific rate. Within the simulation it records inputs into a buffer, dequeues them in order, ticks Physics.Simulate on a fixed time and keeps everything nice and isolated.

The inputs get stored and compressed into a file and decompressed if you run in playback mode and reinjected during the simulation loop. As a result you can play back the inputs as fast as you want and it doesn’t matter what your framerate does. The debug data is simply on three of the dude’s positions. I’ve run this many times on different entities, recorded different data, tinkered with physics settings like depen velocities and it seems to be consistently replaying things.

Anyway, just some interesting thing I did. I’ve seen a lot of posts about physics being non deterministic but it appears that when you control the rate at which things operate then you’re quite able to make it deterministic.

Thx for posting.
This is interesting, as I am looking in such solution in the future.