Okay, so another long post, but I have found a solution that’s available in today’s Corona!
(1) Separation-free Ragdolls on other Box2D implementations.
First off, if anyone has a solid working example in Cocos2D, please send it my way.
As I mentioned previously, I have seen problems in alternative Box2D implementations including Cocos2D *and* Flash. I saw some assertion that this was unique to Corona, but I have not found a solid sample. Again, if there is one, I’d love to see what’s different about that setup. I have a feeling any working sample will do what I discuss in #3 below.
(2) Separation due to limitations of Box2D
Second, I found some relevant data about instability (i.e. separation) from 2 authoritative sources.
* From iforce2d (who’s clearly an expert on Box2D, given the number of excellent discussions on the site): You may get instability problems if you try to pull a heavy body with a lighter body.
* From Erin Catto: Chains of bodies connected by joints may stretch if a lighter body is supporting a heavier body. For example, a wrecking ball connect to a chain of light weight bodies may not be stable. Stability degrades as the mass ratio passes 10:1.
These both describe the sources of instability that I’m seeing. When you drag the ragdoll by the bicep, I’m able to get some instability. And this makes sense b/c you’ve got over 10 times the mass attached to it, i.e. the rest of the body attached to the relatively ligher mass of the bicep.
(3) A Solution!
Finally, I found a solution. Erin Catto (creator of Box2d) suggests on this thread (http://www.box2d.org/forum/viewtopic.php?f=3&t=1499) to turn off continuous physics for some guy having problems with pivot (prismatic) joints. So on a lark I tried turning it on:
physics.setContinuous( false )
Voila! This seems to eliminate the instability and joint separation! If I crank up the maxForce on the touch joints (which seemed to exacerbate separation/instability under continuous physics), everything’s still fine. I also confirmed this by modifying the Cocos2D sample project as well. Again, no separation.
Okay, so what’s the catch? The catch is that continuous physics prevents objects from “tunnelling” where an object (e.g. a bullet) moves so quickly that it appears to move through a thin wall. Continuous physics prevents this, but there are apparently instability issues with joints. Turning it off makes the instability go away. However, you’ll want to make your static bodies extra thick to prevent tunneling effects
In my case, when I turned off continuous physics, I’d move the ragdoll so quickly, that half the ragdoll would be on one side of the wall and half would be on the other side — all because my walls were only 1 pixel thick! Making the walls 100 pixels thick prevented the tunneling.
So the trade-off seems to be: tunneling vs instability on joints.
Happy coding! [import]uid: 26 topic_id: 3208 reply_id: 110810[/import]