First of all I am new here and thanks for reading this.
I have written a game to do some simulation of two cars crashing each other. What I want to achieve is to keep the result the same every time I run the simulation as long as I don't change the settings of the cars and the environment, but obviously it's not something I am getting now.
Does anyone have any idea why is that and what can I do to achieve that?
Thanks!!
i think you can't. you must wright your own engine or somthing, which will be much more simplier then box2d. you can reed manual and understend, that box have many approximations.
as example - if you know result you want - you can build simulation, that will approximate your result (not result depends from start conditions, but simulation itself seeks approximation of result)
but i could be wrong.
I haven't tested this, but just a hunch - how are you stepping through the simulation? Are you using deltaTime? That is, time since the previous frame? If so, then it will be slightly different each time depending on how quickly your graphics card can update that frame. Instead, you can update at a fixed interval - the display might get choppy or jittery, but it should be more consistent.
Last couple of posts are indeed correct. I think there's an iforce2d blog post somewhere that shows a table on how the differences between a 1/5 second timestep and a 1/10 second timestep, and how the final position of an object is different between the fixed timesteps, even though the acceleration is the same. I can't seem to find it, but it illustrates how big a difference it is between two different timesteps, let alone having a variable timestep.
Also, Box2D does some caching of things that depend on a fixed timestep, so yeah.
Of course, this all assumes you're using a variable timestep. If you're already using fixed timestep, then one most common reason why the simulations are not the same is that the simulations do not have the exact same setup. If you add all of the bodies and stuff before the first timestep in both simulations, then both simulations should end up the same way. If your second simulation is different in that you add some or all bodies after the first timestep instead of before, then the second simulation can be different from the first.
try with the time stamp then it might be okay