Ragdoll continuous movement
        Posted  
        
            by 
                Siddharth
            
        on Game Development
        
        See other posts from Game Development
        
            or by Siddharth
        
        
        
        Published on 2012-05-30T07:54:42Z
        Indexed on 
            2012/05/30
            17:02 UTC
        
        
        Read the original article
        Hit count: 434
        
andengine
I have created a ragdoll for my game but the problem I found was that the ragdoll joints are not perfectly implemented so they are continuously moving. Ragdoll does not stand at fix place. I here paste my work for that and suggest some guidance about that so that it can stand on fix place.
    chest = new Chest(pX, pY, gameObject.getmChestTextureRegion(),
            gameObject);
    head = new Head(pX, pY - 16, gameObject.getmHeadTextureRegion(),
            gameObject);
    leftHand = new Hand(pX - 6, pY + 6, gameObject.getmHandTextureRegion()
            .clone(), gameObject);
    rightHand = new Hand(pX + 12, pY + 6, gameObject
            .getmHandTextureRegion().clone(), gameObject);
    rightHand.setFlippedHorizontal(true);
    leftLeg = new Leg(pX, pY + 18, gameObject.getmLegTextureRegion()
            .clone(), gameObject);
    rightLeg = new Leg(pX + 7, pY + 18, gameObject.getmLegTextureRegion()
            .clone(), gameObject);
    rightLeg.setFlippedHorizontal(true);
    gameObject.getmScene().registerTouchArea(chest);
    gameObject.getmScene().attachChild(chest);
    gameObject.getmScene().registerTouchArea(head);
    gameObject.getmScene().attachChild(head);
    gameObject.getmScene().registerTouchArea(leftHand);
    gameObject.getmScene().attachChild(leftHand);
    gameObject.getmScene().registerTouchArea(rightHand);
    gameObject.getmScene().attachChild(rightHand);
    gameObject.getmScene().registerTouchArea(leftLeg);
    gameObject.getmScene().attachChild(leftLeg);
    gameObject.getmScene().registerTouchArea(rightLeg);
    gameObject.getmScene().attachChild(rightLeg);
    // head revolute joint
    revoluteJointDef = new RevoluteJointDef();
    revoluteJointDef.enableLimit = true;
    revoluteJointDef.initialize(head.getHeadBody(), chest.getChestBody(),
            chest.getChestBody().getWorldCenter());
    revoluteJointDef.localAnchorA.set(0f, 0f);
    revoluteJointDef.localAnchorB.set(0f, -0.5f);
    revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI));
    revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI));
    headRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld()
            .createJoint(revoluteJointDef);
    //
    // left leg revolute joint
    revoluteJointDef.initialize(leftLeg.getLegBody(), chest.getChestBody(),
            chest.getChestBody().getWorldCenter());
    revoluteJointDef.localAnchorA.set(0f, 0f);
    revoluteJointDef.localAnchorB.set(-0.15f, 0.75f);
    revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI));
    revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI));
    leftLegRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld()
            .createJoint(revoluteJointDef);
    // right leg revolute joint
    revoluteJointDef.initialize(rightLeg.getLegBody(),
            chest.getChestBody(), chest.getChestBody().getWorldCenter());
    revoluteJointDef.localAnchorA.set(0f, 0f);
    revoluteJointDef.localAnchorB.set(0.15f, 0.75f);
    revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI));
    revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI));
    rightLegRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld()
            .createJoint(revoluteJointDef);
    // left hand revolute joint
    revoluteJointDef.initialize(leftHand.getHandBody(),
            chest.getChestBody(), chest.getChestBody().getWorldCenter());
    revoluteJointDef.localAnchorA.set(0f, 0f);
    revoluteJointDef.localAnchorB.set(-0.25f, 0.1f);
    revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI));
    revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI));
    leftHandRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld()
            .createJoint(revoluteJointDef);
    // right hand revolute joint
    revoluteJointDef.initialize(rightHand.getHandBody(),
            chest.getChestBody(), chest.getChestBody().getWorldCenter());
    revoluteJointDef.localAnchorA.set(0f, 0f);
    revoluteJointDef.localAnchorB.set(0.25f, 0.1f);
    revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI));
    revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI));
    rightHandRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld()
            .createJoint(revoluteJointDef);
        © Game Development or respective owner