Correct way to stop a dynamic object?

Hi!

I our game we have dynamic objects that have initial positions, and then, when the player collides with them, they start flying around. If the player clicks "Restart Level" I want those objects to be reset at their original positions and their forces "reset" to what they were when the level was created, ie. the object completely stopped.

What is the correct way to reset the forces? I am using body::setXForm() to set the positon and angle and then body::putToSleep() and directly after that body:wakeUp() to reset the forces but the objects sometimes seem to have some small forces that are not reset. Eg. a pile of barrels stands still when loading the level the first time, but falls over by itself after a while after restarting the level.

So, what is a good way to make a dynamic object behave as if it was just created and no forces yet applied to it.
For resetting the level to its initial state, it seems to me the most logical solution would be simply to destroy everything in the world and then recreate it from scratch (at least that's what I'd do).

As for 'resetting' an existing object, up until recently at least there was a 'reset forces' function that could be called explicitly where needed. I'm not sure if this function is in the latest version, but if it is, perhaps you could call it when the level is reset to ensure that there are no 'leftover' forces when the simulation starts up again.
Aren't forces automatically reset between every step ?
Gnurfos wrote:
Aren't forces automatically reset between every step ?

They were, and then they weren't - in one of the recent versions of Box2D, you had to manually call a 'clear forces' function whenever you wanted the forces to be reset.

I haven't downloaded the latest version yet, so I don't know if this is still the case.

Original thread: https://box2d.org/forum/viewtopic.php?t=4876