2016-08-21 26 views
0

我試圖創建電梯。我使用PrismaticJointDef但身體A具有相同的身體B的位置。如何定義兩個身體之間的距離?我也使用了DistanceJointDef,但得到相同的結果。 我想得到像這樣的視頻這樣的結果。 https://www.youtube.com/watch?v=rzNjNBKYuGI在libgdx中使用棱柱關節

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); 

回答