Search code examples
libgdxbox2d

LibGdx box2d How can I change bodys size without changing weight?


I had everything in real lifes size, but i saw that it's a bit small so I wanted to make it 1.5 times bigger, but now the soccer ball is too heavy and I want it to be the excact weight as it was before.

These are the specs that I need to change:

ballShape.setRadius(0.2f);

fixtureDef.density = 0.420f;


Solution

  • Let's do some math!

    The ball's radius is 0.2. The volume of the sphere is 4/3*pi*r^3, so in our case it's 0.034.

    With a density of 0.420, our ball weighs 0.01428.

    You want to keep the weight of the ball, but change the size of it, so you need to change the density.

    The density you will need is 0.01428/4/3*pi*0.3^3, wich equals 0.126.