Restarting simulation

Topics: Developer Forum
Jan 23, 2011 at 2:50 AM

Just a quick question:


If you let the world run for a few time step.  

Save position and velocities of all bodies. 

Create a new World, create same bodies and set thier position and velocities (including angular) will you get the same motion or will it be slightly different.

I expect that at worse you would get very similar behavior, but will you get the exact behavior?

To put it another way, is there some information/state which is passed from one time step to another?


Jim K

Jan 23, 2011 at 6:07 PM

There are no information shared between steps. Give it some input data and it will simulate the exact same way each run. (given the same parameters and timing)

Jan 24, 2011 at 12:50 AM


Then I am missing something which needs to be save and  restored.

I have a unit test which creates a simulation of 8 bodies connected by joints (similar to rag doll example with different joints).

I create an run a simultion with a number of steps.

Save the current state of the simulation.

Start a collection of stats about the collections locations and velocity.

Run for a number of additional steps.

Snap shot the stats.

Restart the simulation using save state.

Start a collection of stats on this new collection of locations and velocity.

Run for same number of additional steps.

Compare 2 sets of stats. When I compare these number they are different by about 0.2%.


The information I am saving is current location and velocity with angular components of each body.

I would think that I could have restored the system incorrectly, but until just recently I was using a different physics engine (physics2d) but I decide to port to Farseer.  This is the last test to resolve before I am done with the port.

This test existed in the previous incarnation and I would get the exact same results, but not with Farseer.

Any ideas of what I am not saving and restoring?

Any help would save me alot of time to look at every possibility.


Jim K.

Jan 25, 2011 at 4:23 AM

Sorry, but this is important to me

I have been doing some checking and after restarting everything is the same except 2 components.

Sweep.A0 and Sweep.C0.

These values are different after I recreate and set the bodies (Vel,position,angles)

After I set the bodies/shapes information Sweep.A0 == Sweep.A and Sweep.C0 == Sweep.C

but if I look in the middle if the baseline simulation, these are not equal.

Any thoughts?



Jim K.

Jan 25, 2011 at 12:48 PM

I see.

Could you try to disable CCD and warmstarting by turning them off inside Settings.cs?

If the test still fails, can you create a testbed test (use the FPE 3.2 project from the Downloads tab) that shows the problem?

Jan 25, 2011 at 4:42 PM

I think I have it tracked down.

The Sweep.A0 and Sweep.C0 were false leads.  They are being reset each time internally.  So, the fact that they had different values going into the step did not matter.

The real source is the Joints (RevoluteJoint).  They are conveying information from one step to the next in the internal member variables  _motorImpulse, _motorMass, and _implse.  IslandFlag is also different but I am not sure if that matters.

The real issues is how to fix this.  These are all internal values and can't be set externally.


Jim K.

Jan 25, 2011 at 4:53 PM

Is this for save games or replays?

The revolute joint come from Box2D, so you might want to ask on the Box2D forums about this. The reason I needed a test of it was to confirm that the behavior in FPE 3.2 is identical to the behavior in Box2D - if they are the same, then you need to ask on the Box2D forums instead.

If I remember correctly, the variables you mention are only carried between steps with warmstarting. Warmstarting is only to make the iterative solvers guess closer to the final result. Again, try disabling warm starting.

Jan 25, 2011 at 4:59 PM



This is to replay.  What I am writing is a simulation not a game and I need to be able to save state in the middle for more detail analysis.

I will try turning off warm start.  Looking at the code, I think this may work.


Thanks again. Its been very helpful and it would have taken me more time to figure it out with out your help.

Jim K.