1
\$\begingroup\$

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.position.set(getX(),getY());
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body=world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(6/Advanture.PPM);
    b2body.createFixture(fdef).setUserData(this);


}

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


  }

......    
 }   
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

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