- Home /
I have a question for unity physics can simulate always same result with same input?
I'm trying to make physics based online sports game. my question is this, in my project, i set Physics.autoSimulation as false, and i simulate physicsScene manually and save every inputs per simulation to file. can i get perfectly same simulation result with this saved input data and manual physics simulation?
does unity physics always calculate perfectly same simulation result with same simulation time step and inputs?
Answer by lgarczyn · Jan 03, 2020 at 01:41 AM
Technically, yes. However you need to make sure that inputs are stored then applied on FixedUpdates only, because Update timings are extremely variable.
On Update each input event should be added to a list, with an ID matching a specific FixedUpdate. You can calculate that ID using a simple counter that increments every FixedUpdate.
Each FixedUpdate, check if there's an input with the same ID, and apply it. This works both for the original gameplay and the replay.
Any random event should use a random number generator using the same seed. Lookup System.Random.
To store Inputs you should probably use a dictionary, with the ID as the key, and a strict containing all your input data as the value.
Answer by NorthStar79 · Jan 03, 2020 at 05:35 AM
No, Although if you follow everything @ceandros you will get almost identical simulations on the same device with a similar workload. But if you try to save inputs and expect to see same physics behavior on different devices across all player, you are out of luck as long as you use PhysX
There's been a lot of discussion on how predictive the physics engine is, but in the latest version people have had trouble getting different results even on different devices. It would be interesting to actually test this in depth.
Your answer
Follow this Question
Related Questions
Server runs physics, client only receives position data 0 Answers
Photon Unity Networking fix physics delay 0 Answers
Instantiate By ID? 0 Answers
RPC custom server best practice 1 Answer
Applying proper drag and center of mass for a vehicle 1 Answer