我写了一个简单的游戏使用Libgdx和Box2d。我的主要代码在这里:
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.StaticBody;
bodyDef.position.set(new Vector2(mainGear.getX()
+ mainGear.getOriginX(), mainGear.getY()
+ mainGear.getOriginY()));
body = world.createBody(bodyDef);
float r = 231.5f;
Vector2[] vertexs = new Vector2[36];
for (int i = 0; i < 36; i++) {
vertexs[i] = new Vector2(MathUtils.cosDeg(10 * i) * r,
MathUtils.sinDeg(10 * i) * r);
}
ChainShape shape = new ChainShape();
shape.createLoop(vertexs);
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.friction = 0.5f;
fd.density = 1;
body.createFixture(fd);
// Dynamic Body
BodyDef bodyDef1 = new BodyDef();
bodyDef1.type = BodyType.DynamicBody;
bodyDef1.position.set(200, 350);
body1 = world.createBody(bodyDef1);
CircleShape dynamicCircle = new CircleShape();
dynamicCircle.setRadius(16f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicCircle;
fixtureDef.density = 1f;
fixtureDef.friction = 0.5f;
fixtureDef.restitution = 0.5f;
body1.createFixture(fixtureDef);
但是当我旋转大圆圈时,小圆圈仍然正常移动,就像我不旋转一样。看起来2圈之间的摩擦不起作用。我想要的是当我向右(或左)旋转大圆圈时,摩擦会拉动小圆圈跟随它。