I am developing a bike game, and i am working at my bike. The bike chassis is made using the Physics Body Editor tool. Creating the chassis
void createChasis(World world, Sprite sprite) {
BodyEditorLoader loader = new BodyEditorLoader(
Gdx.files.internal("data/motor/bike"));
BodyDef bd = new BodyDef();
bd.position.set(0, 4);
bd.type = BodyType.DynamicBody;
FixtureDef fd = new FixtureDef();
fd.density = 0.2f;
fd.friction = 0.1f;
fd.restitution = 0.4f;
chassis = world.createBody(bd);
loader.attachFixture(chassis, "motor", fd, 2);
chassis.setUserData(sprite);
}
And the constructor of the Motor class
public Motor2D(World world) {
float width = 2;
float height = 1;
FixtureDef chassisFixtureDef = new FixtureDef();
chassisFixtureDef.density = 1;
chassisFixtureDef.friction = 1;
chassisFixtureDef.restitution = 0.1f;
FixtureDef wheelFixtureDef = new FixtureDef();
wheelFixtureDef.density = 0.6f;
wheelFixtureDef.restitution = 0.1f;
wheelFixtureDef.friction = 2f;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(0, 5);
// chassis
Sprite roata, cadru;
Texture textura = new Texture(Gdx.files.internal("data/texture.PNG"));
cadru = new Sprite(new TextureRegion(textura, 0, 0, 500, 264));
roata = new Sprite(new TextureRegion(textura, 0, 254, 178, 178));
cadru.setOrigin(cadru.getWidth() / 2, cadru.getHeight() / 2);
roata.setOrigin(roata.getWidth() / 2, roata.getHeight() / 2);
createChasis(world, cadru);
// left wheel
CircleShape wheelShape = new CircleShape();
wheelShape.setRadius(height / 3.5f);
// wheelShape.setPosition(new Vector2(1, 1));
wheelFixtureDef.shape = wheelShape;
leftWheel = world.createBody(bodyDef);
leftWheel.createFixture(wheelFixtureDef);
leftWheel.setUserData(roata);
// right wheel
// wheelShape.setPosition(new Vector2(2, 1));
rightWheel = world.createBody(bodyDef);
rightWheel.createFixture(wheelFixtureDef);
rightWheel.setUserData(roata);
// left axis
// create axes
WheelJointDef axisDef = new WheelJointDef();
axisDef.bodyA = chassis;
axisDef.localAnchorA.set(-width , -height / 2);
axisDef.bodyB = leftWheel;
axisDef.localAxisA.set(Vector2.Y);
axisDef.frequencyHz = 1.75f;
axisDef.motorSpeed = motorSpeed;
leftAxis = (WheelJoint) world.createJoint(axisDef);
axisDef.bodyB = rightWheel;
axisDef.localAnchorA.x *= -1;
rightAxis = (WheelJoint) world.createJoint(axisDef);
}
I tried to change axisDef.localAnchorA but i still can't do this.
I want something like this
Can anyone help me?