I use libGdx/box2d’s physic. My intention is to create a balloon filled with helium (a body, what hovers above a surface, if we apply a little force to it – it moves fast but not far, if we push against a obstacle – it collide and jump back (restitution)).
I was suggested to use linearDamping or gravityScale to achieve similar behavoir.
So far I achieved a ball behavior: it hovers, it moves (not as intended, just simple move), but no restitution. Here my code:
mBallDef = new BodyDef();
mBallDef.type = BodyType.DynamicBody;
mBallDef.position.set(x, y);
mShape = new CircleShape();
mShape.setRadius(radius);
mFixDef = new FixtureDef();
mFixDef.shape = mShape;
mFixDef.density = 0.7f;
mFixDef.friction = .5f;
mFixDef.restitution = .8f;
mBall = world.createBody(mBallDef);
mBall.setActive(true);
mBall.setAwake(true);
mBallFix = mBall.createFixture(mFixDef);
mBall.setGravityScale(.2f);
mBall.setLinearDamping(5.5f);
Touch implementation (just moves a balloon up, it’s for test, nothing special)
Gdx.input.setInputProcessor(new InputHandler()
{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button)
{
mBall.applyLinearImpulse(0, 15.5f, mBall.getWorldCenter().x + mShape.getRadius(),mBall.getWorldCenter().y - mShape.getRadius(), true);
mBall.setAngularVelocity(0);
return true;
}
});
When I use for gravity – .2f and for linearDamping – 5.5f, a ball hovers, but I loose a restitution for my balloon. The restitution is available only for linearDamping below 1.5f. And I was told that it’s not good practice to keep gravity far away from 1.
My experiment with FixtureDef.density failed, changing it to various values (grom -2 to 2) has no visible effect.
The questions are:
1) What’s use of density? It doesn’t provide visible affect.
2) What values I should declare to create balloon ligher than air?