After watching the video about iChalky I set about creating a similar system using box2D. I noticed on the
wiki it talks about maintaining a desired angle on a joint.
I've starting writing my own Game Engine within AS3, using the TestRagdoll example as a base for characters/ players.
Constructor for my Doll class creates all the bodies / Revolute Joints with
Code:
joint.enableMotor = true; joint.maxMotorTorque = 0.0;
So that the Doll (all bodies) acts as a rag doll until the Game loop.
During the Game Loop I've used this code per leg and torso (bodies):
Code:
// ... Game Loop Begin ...
var angleError:Number = joint.GetJointAngle() - angleTarget;
var gain:Number = 0.1;
joint.SetMotorSpeed(-gain * angleError);
joint.maxMotorTorque(20);
// ... Game Loop End ...
angleTarget being almost
0.0 . The Revolute Joint motors now work to keep the legs at the correct angle to keep the player upright.
When the player's overall angle becomes too large
angleTarget gets increased so that the player's legs stand apart more to stabilise itself.
(swf coming soon, once I get time to upload).