- Home /
Transforming non deterministic game to deterministic
hello, so I'm making a game where you run a complexe simulation then the player can pause the simulation then modify some things then play it again the game is realy advanced already. Obviusly people keep on telling me i should make it deterministic. If It where deterministic it would be so much better...I would finely be able to rest my concience. I'm willing to suffer to achieve this. The only thing I don't know exactly what I need to do to make it deterministic. There are meny things im having doubtes about.
The game uses code that executes at specifique moments of the animations. I geuse I'm going to have to change that? and execut it in the FixedUpdate().
I geuse I need to change the game so all simulation related elements execute in the fixedUpdate and it uses Time.fixedtime and Time.fixedDeltaTime?
Can I keep my trigger collisions against rigidbodys ?
For pathFinding my game currently uses the default unity path finder.Can I keep this? If no I geuse i can still use it to finde the path. Im just going to have to recode the part where I move the object to folow the path?
For physics. I currently need a 3d simple box collide against 3d box phyics and also I need to push the boxes with force given from scripts. I Have heard that the unity physics can be deterministic in specifique circomtances. But from what I can tell its going to be hard for me to use them. Considering that I Think that just changing the time speed makes the physics no longer deterministic. From what I can tell. A,d if the frame rate goes lower then 3 it is no longer deterministic. Wich could cause problemes. Also I instansiate objects mid simulation, im worried this could cause problemes. And I need to move the transform objects that teleport around. So what are my options for the physics?
I need to make sure all the fixed updates of every gameobject executes in the same order. Is it a good idea to just make one object's script call a MyFixedUpdate() methode in maney others?
Do I need to worry about using float maths instead of integer maths considering the game just needs to run simulations on the same device?
Is changing the time speed from 1 to 0 and 1 to 0 going to cause problemes is there anything I can do.?
Is there anything else that im going to have to deal with that I havent even thought of?
So thanks in advance. I'll take all the help I can get.
Answer by Eno-Khaon · Apr 24, 2018 at 08:17 PM
If you're looking for an absolutely deterministic setup, where all possible outcomes can be reproduced without fail by providing matching inputs, you'll first need a fixed framerate to ensure that input and reactions to input can all land at the same time intervals.
For that, you could use Time.captureFramerate to lock the framerate, where gameplay would slow down if that framerate is not reached (technically, it's intended more for frame-by-frame video capture).
To further attempt to provide matching physics capability, you may want to trigger all physics simulations yourself. This can be done through a combination of Physics.Simulate() and Physics.autoSimulation.
(Note that the Physics.Simulate() documentation also notes conditions which break a deterministic intent)
thanks for your answer it makes me feel obtimistic that what I'm trying to achiev wont be impossible..All what I would have to do is update the rest of the game at the same rate as the physics. make sure the pathfinder uses physics to folow the way points. Then only move transformes via rigidObj.$$anonymous$$ovePosition(). Then I think It would all possibly becom deter$$anonymous$$sitic. praise the lord this works. I shall report my findings. I want it to be perfectly deter$$anonymous$$istic that would be ideal but if its more deter$$anonymous$$istic then befor thats already a good thing for my game. Im only a bit confused on the use of Time.captureFramerate . Dont realy Understand why one would need to use it .
Time.captureFramerate is there to enforce a gameplay framerate. For example, if you wanted it to run at exactly 60 frames per second, then 60 frames would always be processed for every second of "Game Time" spent.
If performance is good, it would simply act as a framerate cap, limiting you to 60 frames per second.
However, if you had a framerate of, say, 30, then everything would run slowly (at half speed by that example) in order to ensure that every frame relative to the target 60 frames-per-second target is rendered. If your framerate is 30 with a captureFramerate of 60, then Time.time will report 1 second after 2 seconds have elapsed.
The example case described in their documentation is for recording videos; you render each frame and save a screenshot of each frame, then even if the screenshot process slows down the render (or if the scene is too busy for the computer it's run on), you still wind up with a smooth video/series of images, as if the game was running at the target framerate.
The reason I describe it as a possible approach is that it allows Update() to be given a fixed timestep of a sort. If someone performs a specific action 3 seconds into a game, you can know that it would take place on (for example) the 180th frame of gameplay. With absolute, precise ti$$anonymous$$g in that regard, gameplay can be replicated accurately with identical inputs.
It would force a fixed framerate, obviously, which isn't always a desirable approach. The more explicitly you wish for gameplay elements to be reproducible, the more limits need to be imposed, depending on the engine.
Unity's rendering and logic (scripts, including input handling) all run on the same thread, so strict enforcement of ti$$anonymous$$g *can* mean a fixed framerate.
Thanks alot, I tride just using Time.captureFramerate = 60 but obviuslly it wasent enof I'll start making sirius attemps in july. For now Im finishing other aspects of the game and gathering as much intel as i can on the matter.
Your answer
Follow this Question
Related Questions
How to make first-person work in zero-G with planets? 1 Answer
How to Draw a line and make a 3D character follow it 1 Answer
Clarification on updates, physics events order and frequency? 1 Answer
Physics2D bug or something I can avoid? 3 Answers
How to find if a point can react another point without hitting a collider 0 Answers