I am trying to create a pendulum using box2d/libgdx by connecting a static and a dynamic body. I have tried various types of joints like distance joint, rope joint and revolute joint but under gravity the dynamic body always ends up escaping down after initially being constrained by the joint. Only in zero gravity the joints work properly. I know I must be doing something really silly.
world.getBodies(p);
DistanceJointDef djd=new DistanceJointDef();
djd.bodyA=p.get(0);
djd.bodyB=p.get(1);
djd.localAnchorA.set(0,0);
djd.localAnchorB.set(0,0);
djd.collideConnected=true;
DistanceJoint pend=(DistanceJoint)world.createJoint(djd);
pend.setLength(50);
PS. I have to yet implemented a contact listener .I have not figured out how to do this. Will putting up a collision listener help?