Jack in the box

Hey guys.

I'm trying to create a jack in the box using Box2D - I thought it would be rather straight-forward, but, seems I was wrong, heh.

I'm using the latest trunk version of Box2D so I have access to the soft-weld joint; I used it to create a vertical cantilever which mimics a loose metal spring with a heavy weight on top - this seems to work nicely to create the effect of the spring bending around after it pops out.

The issue I'm having is how to get it to "pop" out of the box. Basically, I'm not doing it like it would be in real life (the object & spring pushing against the top of the box); the box is a solid static box which creates the spring & weight (all of them don't collide with each other) when it pops open. I can't seem to make it actually "pop out" and push against the objects that are resting on top of it though.

My current "best" attempt is to create the objects as they are in pop-up state, then set the transform of the spring pieces & the weight inside the box.. but that doesn't have the effect of popping the weight up over time; on the first Step it simply pushes all of the chain pieces up and doesn't really apply the "velocity" I'm looking for.

Anybody done this before and might have some insight?

-P
I tend to think that mimicking the way things works in real life (at least as a first attempt) is a good way to get a realistic looking outcome. I tried this with a chain of squarish segments each joined by a revolute joint and a distance joint and it seems to work fairly well. The revolute joint is in the middle like any regular chain, and the distance joint is offset to the side a bit, with frequency and damping adjusted. Actually, I found it was necessary to have a distance joint on each side to prevent the chain from getting kinks in it when stuffed into the box.

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