issue with gravity in andengine android

85 Views Asked by At

I attempting to write simple game that include player sprite and obstacles. I have implemented a physics world with gravity. I would like when player sprite falling it will be near the obstacle where it falling from, but with gravity the the sprite falling in diagonal and not straight down.

mPhysicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);
...

public Player(PhysicsWorld world, final float pX, final float pY, final TiledTextureRegion pTextureRegion,
        final VertexBufferObjectManager pVertexBufferObjectManager)
{
    super(pX, pY, pTextureRegion, pVertexBufferObjectManager);

    mPlayerDeff = PhysicsFactory.createFixtureDef(0, 0, 0);

    mVertexBuffer = pVertexBufferObjectManager;
    mBoardManager = BoardManager.getInstance();
    mDirection = DIRECTION_RIGHT;

    mWorld = world;

    mBody = PhysicsFactory.createBoxBody(mWorld, this, BodyType.DynamicBody, mPlayerDeff);
    mWorld.registerPhysicsConnector(new PhysicsConnector(this, mBody, true, false));

}

current state and wanted state

1

There are 1 best solutions below

0
On

You can try to set mass data to your body:

MassData mass = new MassData();
mass.mass = 10; // in kilograms

mBody.setMassData(mass);