2

Currently, mass on a figure is set using the area of the shape and its density. How can i set the mass if I already know it?

I have tried creating a fixture with a box shape with a certain mass using

 public FixtureDef  createfixture()
{
    PolygonShape ps = new PolygonShape();

    ps.setAsBox(w*12.5f, h*12.5f, new Vec2(attachx,attachy), (float) Math.toRadians(atrot));

    float area = (w*12.5f)*(h*12.5f);

    FixtureDef fd = new FixtureDef();
    fd.density=mass/area;
    fd.shape=ps;

    return fd;
}

However, the mass of the body when i call getmass() is not correct.

1 Answers1

1

The setAsBox width and height are only half the dimensions of the box. That is, the box is twice the width and twice the height. Therefore, you need to multiply your area by 4.0.

nathan
  • 11
  • 1