- Home /
Non deterministic simulation ?
Hello, I am working on a project of a 3D vehicle simulation which uses an algorithm for driving itself. At each frame -in an Update() function-, the algorithm receives inputs (from vehicle sensors) and computes its new position in function of the inputs.
In this way, I except the trajectory of my vehicle to be always the same when it starts from the exact same position. However, I notice that the trajectory is slightly different...
I printed the position of the vehicle at each frame : it is the same for the (e.g) 50 first frames (it can be 40 or 60) and start getting different after then.
Is it possible that the Unity engine makes it non-deterministic? If so, is there a way to make it deterministic?
Thank you
Answer by Bunny83 · Sep 13, 2017 at 10:26 AM
uses an algorithm for driving itself
Uhm what does that mean? Do you use Time.deltaTime in your calculations? If so the simulation won't be frame-rate bound but time bound.
That's the reason why Unity's physics system uses a constant frame rate which is adjusted to have an exact number of calls per second. This basically is FixedUpdate. Update runs with every visual update while FixedUpdate is "fixed" / adjusted to ensure a certain number of calls per second.
Other than that we can't really answer your question without seeing that algorithm and it's implementation.