我试图编写包含玩家精灵和障碍的简单游戏。 我用重力实现了物理世界。我希望当玩家精灵掉落时,它会靠近它掉落的障碍物,但是在重力作用下,精灵会落在对角线而不是直线向下。
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));
}
答案 0 :(得分:0)
您可以尝试将质量数据设置为您的身体:
MassData mass = new MassData();
mass.mass = 10; // in kilograms
mBody.setMassData(mass);