I trying to create a elevator. I use PrismaticJointDef but body A has same position of body B. How can define distance between two body? I also used DistanceJointDef but get same result. I want get such result like this video. https://www.youtube.com/watch?v=rzNjNBKYuGI
private void defineBodyA(){
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(getX() + getWidth() / 2, getY() + getHeight() / 2);
bodyA = world.createBody(bodyDef);
PolygonShape shape = new PolygonShape();
shape.setAsBox(getWidth() / 2, getHeight() / 2);
fixtureDef.shape = shape;
bodyA.createFixture(fixtureDef);
bodyA.setLinearDamping(30f);
shape.dispose();
}
private void defineBodyB{
bodyDef.position.set(getX() + getWidth() / 2, (getY() + 80 / PPM);
bodyDef.type = BodyDef.BodyType.StaticBody;
bodyB = world.createBody(bodyDef);
PolygonShape upOfElevator = new PolygonShape();
upOfElevator.setAsBox(16f / PPM, 0.5f / PPM);
fixtureDef.shape = upOfElevator;
bodyB.createFixture(fixtureDef);
upOfElevator.dispose();
}
PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
prismaticJointDef.bodyA = bodyA;
prismaticJointDef.bodyB = bodyB;
world.createJoint(prismaticJointDef);
DistanceJointDef distanceJointDef = new DistanceJointDef();
distanceJointDef.bodyA = bodyA;
distanceJointDef.bodyB = bodyB;
distanceJointDef.length = 100 / PPM;
world.createJoint(distanceJointDef);