I am trying to make a body flying

is there any way to change gravity or hold the circle levitating?

Here is the code i'm using:

public class Fly extends Enemy {

   protected void defineEnemy() {
    BodyDef bdef = new BodyDef();
    bdef.type = BodyDef.BodyType.DynamicBody;

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();


public void update(float dt) {
   stateTime +=dt;
   b2body.setLinearVelocity(new Vector2(-1,0));
   setPosition(b2body.getPosition().x - getWidth()/2, 1); 



1 Answer 1


I just found the way of changing gravity.

So, this is done by using b2body.setGravityScale(float number);

If you want to make the body less affected by gravity, it should be b2body.setGravityScale(1/100);

So it depends on number, you can let the character be affected by gravity however much you want.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .