I'm trying to make a vehicle as you can see. But The prismatic and revolute joints won't stay together well.
http://www.youtube.com/watch?v=8VkY0upr5-ECode:
Chassis = new Sprite(450, 100, menuTextures.Chassis1);
final FixtureDef objectFixtureDef = PhysicsFactory.createFixtureDef(1.0f, 0.0f, 1.0f);
objectFixtureDef.restitution = 0.0f;
final FixtureDef pivotDef = PhysicsFactory.createFixtureDef(1.0f, 0.0f, 1.0f);
pivotDef.restitution = 0.0f;
final FixtureDef wheelDef = PhysicsFactory.createFixtureDef(1.0f, 0.0f, 5.0f);
wheelDef.restitution = 0.0f;
final ITriangulationAlgoritm triangulationAlgoritm = new EarClippingTriangulator();
final float width = Chassis.getWidthScaled() / PIXEL_TO_METER_RATIO_DEFAULT;
final float height = Chassis.getHeightScaled() / PIXEL_TO_METER_RATIO_DEFAULT;
List<Vector2> mVertices = new ArrayList<Vector2>();
mVertices.add(new Vector2(-0.39844f*width, -0.14648f*height));
mVertices.add(new Vector2(-0.37500f*width, -0.14648f*height));
mVertices.add(new Vector2(+0.02344f*width, -0.16406f*height));
mVertices.add(new Vector2(+0.06152f*width, -0.17773f*height));
mVertices.add(new Vector2(+0.06348f*width, -0.10938f*height));
mVertices.add(new Vector2(+0.09375f*width, -0.12500f*height));
mVertices.add(new Vector2(+0.18945f*width, -0.12305f*height));
mVertices.add(new Vector2(+0.32812f*width, +0.07422f*height));
mVertices.add(new Vector2(+0.21484f*width, +0.04883f*height));
mVertices.add(new Vector2(+0.37695f*width, +0.11914f*height));
mVertices.add(new Vector2(+0.39844f*width, +0.29688f*height));
mVertices.add(new Vector2(+0.37793f*width, +0.29492f*height));
mVertices.add(new Vector2(+0.39746f*width, +0.37109f*height));
mVertices.add(new Vector2(+0.34375f*width, +0.37305f*height));
mVertices.add(new Vector2(+0.21875f*width, +0.37500f*height));
mVertices.add(new Vector2(+0.21875f*width, +0.41016f*height));
mVertices.add(new Vector2(+0.02344f*width, +0.22461f*height));
mVertices.add(new Vector2(-0.36133f*width, +0.45312f*height));
mVertices.add(new Vector2(-0.36816f*width, +0.43750f*height));
mVertices.add(new Vector2(-0.35547f*width, +0.40430f*height));
mVertices.add(new Vector2(-0.35645f*width, +0.22461f*height));
final List<Vector2> triangles = triangulationAlgoritm.computeTriangles(mVertices);
final Body chassisBody = PhysicsFactory.createTrianglulatedBody(mPhysicsWorld, Chassis, triangles, BodyType.DynamicBody, objectFixtureDef);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(Chassis, chassisBody, true, true));
final Shape leftJointShape = new Rectangle( Chassis.getX()+ Chassis.getWidth() - 210, Chassis.getY()+ Chassis.getHeight() - 35, 10, 25);
final Body leftAnchorBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, leftJointShape, BodyType.DynamicBody, pivotDef);
leftAnchorBody.setTransform( new Vector2( leftAnchorBody.getWorldCenter().x, leftAnchorBody.getWorldCenter().y ), 60f); // change rotation
final Shape rightJointShape = new Rectangle(Chassis.getX()+ Chassis.getWidth() - 70, Chassis.getY()+ Chassis.getHeight() - 35, 10, 25);
final Body rightAnchorBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, rightJointShape, BodyType.DynamicBody, pivotDef);
rightAnchorBody.setTransform( new Vector2( rightAnchorBody.getWorldCenter().x, rightAnchorBody.getWorldCenter().y ), 125f); // change rotation
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(leftJointShape, leftAnchorBody, true, true));
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(rightJointShape, rightAnchorBody, true, true));
final Sprite WheelLeft = new Sprite(Chassis.getX()+ Chassis.getWidth() - 215, Chassis.getY()+ Chassis.getHeight() - 25, menuTextures.Wheel1);
final Body leftWheelBody = PhysicsFactory.createCircleBody(this.mPhysicsWorld, WheelLeft, BodyType.DynamicBody, wheelDef);
leftWheelBody.setSleepingAllowed(false);
final Sprite WheelRight = new Sprite(Chassis.getX()+ Chassis.getWidth() - 70, Chassis.getY()+ Chassis.getHeight() - 25, menuTextures.Wheel1);
final Body rightWheelBody = PhysicsFactory.createCircleBody(this.mPhysicsWorld, WheelRight, BodyType.DynamicBody, wheelDef);
rightWheelBody.setSleepingAllowed(false);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(WheelLeft, leftWheelBody, true, true));
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(WheelRight, rightWheelBody, true, true));
scene.getFirstChild().attachChild(Chassis);
scene.getFirstChild().attachChild(leftJointShape);
scene.getFirstChild().attachChild(rightJointShape);
scene.getFirstChild().attachChild(WheelLeft);
scene.getFirstChild().attachChild(WheelRight);
final PrismaticJointDef leftPrismaticJointDef = new PrismaticJointDef();
//leftPrismaticJointDef.initialize(chassisBody, leftAnchorBody, new Vector2(Chassis.getWidth() - 210, Chassis.getHeight() - 25), new Vector2(0, 1.0f)); // the 3rd parameter says where the fuck
//leftPrismaticJointDef.initialize(chassisBody, leftAnchorBody, leftAnchorBody.getWorldCenter(), new Vector2((float)Math.cos(Math.PI/3), (float)Math.sin(Math.PI/3))); // the 3rd parameter says where the fuck
leftPrismaticJointDef.bodyA = chassisBody;
leftPrismaticJointDef.bodyB = leftAnchorBody;
leftPrismaticJointDef.localAnchorA.set(-2.2f, 1.6f);
leftPrismaticJointDef.localAnchorB.set(0, 0);
leftPrismaticJointDef.localAxis1.set(new Vector2((float)Math.cos(Math.PI/3), (float)Math.sin(Math.PI/3)));
leftPrismaticJointDef.lowerTranslation = -0.0f;
leftPrismaticJointDef.upperTranslation = 0.0f;
leftPrismaticJointDef.enableLimit = true;
leftPrismaticJointDef.enableMotor = true;
leftPrismaticJointDef.maxMotorForce = 0;
leftPrismaticJointDef.motorSpeed = 0;
this.mPhysicsWorld.createJoint(leftPrismaticJointDef);
final PrismaticJointDef rightPrismaticJointDef = new PrismaticJointDef();
//rightPrismaticJointDef.initialize(chassisBody, leftAnchorBody, new Vector2(Chassis.getWidth() - 70, Chassis.getHeight() - 25), new Vector2(0, 1.0f)); // the 3rd parameter says where the fuck
//rightPrismaticJointDef.initialize(chassisBody, rightAnchorBody, rightAnchorBody.getWorldCenter(), new Vector2((float)-Math.cos(Math.PI/3), (float)Math.sin(Math.PI/3))); // the 3rd parameter says where the fuck
rightPrismaticJointDef.bodyA = chassisBody;
rightPrismaticJointDef.bodyB = rightAnchorBody;
rightPrismaticJointDef.localAnchorA.set(2.2f, 1.6f);
rightPrismaticJointDef.localAnchorB.set(0, 0);
rightPrismaticJointDef.localAxis1.set(new Vector2((float)-Math.cos(Math.PI/3), (float)Math.sin(Math.PI/3)));
rightPrismaticJointDef.lowerTranslation = -0.0f;
rightPrismaticJointDef.upperTranslation = 0.0f;
rightPrismaticJointDef.enableLimit = true;
rightPrismaticJointDef.enableMotor = true;
rightPrismaticJointDef.maxMotorForce = 0;
rightPrismaticJointDef.motorSpeed = 0;
this.mPhysicsWorld.createJoint(rightPrismaticJointDef);
final RevoluteJointDef leftRevoluteJointDef = new RevoluteJointDef();
//leftRevoluteJointDef.initialize(leftAnchorBody, leftWheelBody, leftWheelBody.getWorldCenter());
leftRevoluteJointDef.bodyA = leftAnchorBody;
leftRevoluteJointDef.bodyB = leftWheelBody;
leftRevoluteJointDef.localAnchorA.set(0,0);
leftRevoluteJointDef.localAnchorB.set(0,-0.5f);
leftRevoluteJointDef.enableLimit = true;
leftRevoluteJointDef.enableMotor = true;
leftRevoluteJointDef.maxMotorTorque = 200;
leftRevoluteJointDef.motorSpeed = 10;
this.mPhysicsWorld.createJoint(leftRevoluteJointDef);
final RevoluteJointDef rightRevoluteJointDef = new RevoluteJointDef();
//rightRevoluteJointDef.initialize(rightAnchorBody, rightWheelBody, rightWheelBody.getWorldCenter());
rightRevoluteJointDef.bodyA = rightAnchorBody;
rightRevoluteJointDef.bodyB = rightWheelBody;
rightRevoluteJointDef.localAnchorA.set(0,0);
rightRevoluteJointDef.localAnchorB.set(0,-0.5f);
rightRevoluteJointDef.enableLimit = true;
rightRevoluteJointDef.enableMotor = true;
rightRevoluteJointDef.maxMotorTorque = 200;
rightRevoluteJointDef.motorSpeed = 10;
this.mPhysicsWorld.createJoint(rightRevoluteJointDef);