LibGDX。 Box2D的。联合旋转或如何制作坦克

时间:2016-05-06 15:50:37

标签: libgdx box2d

我试图使用LibGDX和Box2D进行控制。通过box2d旋转接头连接底盘和塔架。

机箱:

BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.bullet = true;

PolygonShape shape = new PolygonShape();
shape.setAsBox(sizeM.x / 2, sizeM.y / 2);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = MASS / (sizeM.x * sizeM.y);

Body body = world.createBody(bodyDefComponent.bodyDef);
body.createFixture(fixtureDef).setUserData(this);

body.setLinearDamping(DAMPING);
body.setAngularDamping(DAMPING);

塔:

BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.bullet = true;
bodyDef.angularDamping = 3;

PolygonShape shape = new PolygonShape();
shape.setAsBox(sizeM.x / 2, sizeM.y / 2);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = MASS / (sizeM.x * sizeM.y);

Body body = world.createBody(bodyDefComponent.bodyDef);
body.createFixture(fixtureDef).setUserData(this);

联合:

RevoluteJointDef jointDef = new RevoluteJointDef();
jointDef.enableMotor = true;
jointDef.maxMotorTorque = 10000;
jointDef.initialize(mChassis, mTower, new Vector2(position.x, position.y));
Joint joint = world.createJoint(jointDef);

塔式旋转方法:

body.applyAngularImpulse(-ROTATION_POWER, true);

底盘以与塔架相同的方式旋转。底盘旋转时,塔架也会旋转。没关系。但如果我旋转塔架,底盘也会旋转。我也尝试设置无限质量,机器人没有帮助。我猜关节有问题。有什么想法吗?

0 个答案:

没有答案