Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

Box2D – create object with different physic parts

$
0
0

I have object with physic:

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(position);
    bodyDef.angle = angle;
    this.body = world.createBody(bodyDef);

    //init shape
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 1.0f;
    fixtureDef.friction = 0.6f; 
    fixtureDef.restitution  = 2.94f; 
    fixtureDef.isSensor = false;
    PolygonShape carShape = new PolygonShape();
    carShape.setAsBox(this.width / 2, this.length / 2);

    fixtureDef.shape = carShape;
    this.body.createFixture(fixtureDef); `
    addWheels(..);

There is defined carShape like rectangle with physic. Next code is adding wheels. I want add to the center of car another shape or line, which won’t have affect to physic of car and without physic – only rendered but moving with the car. Visible for information purposes only. What is the easiest option to make it?

For example red line:
enter image description here


Viewing all articles
Browse latest Browse all 434

Trending Articles