Libgdx Box2D速度不够快

时间:2013-07-17 13:31:16

标签: java libgdx box2d

我有一个矩形,我想快速移动,但出于什么原因,我使用的速度更快似乎仍然很慢。我究竟做错了什么?我也从上面掉了一个圆圈到一个表面上,甚至比较严厉我玩重力它像气球一样下来......

一些声明

float velocity = 10000000f;
static final float BOX_STEP=1/60f;  
static final int BOX_VELOCITY_ITERATIONS=6;  
static final int BOX_POSITION_ITERATIONS=2;  

重力,尝试了一切,他们似乎都很糟糕

world = new World(new Vector2(0,-50),true);

我的对象正在移动

    //ground
    BodyDef groundBodyDef =new BodyDef();  
    groundBodyDef.position.set(new Vector2(0, camera.viewportHeight * .08f));  
    Body groundBody = world.createBody(groundBodyDef);  
    PolygonShape groundBox = new PolygonShape();  
    groundBox.setAsBox((camera.viewportWidth) * 2, camera.viewportHeight * .08f);  
    groundBody.createFixture(groundBox, 0.0f);   

然后这是我的对象:

    //ball
    bodyDef = new BodyDef();  
    bodyDef.type = BodyType.DynamicBody;  
    bodyDef.position.set(new Vector2(camera.viewportWidth * .2f, camera.viewportHeight * .75f));  
    body = world.createBody(bodyDef);  
    CircleShape dynamicCircle = new CircleShape();  
    dynamicCircle.setRadius(camera.viewportWidth * .035f);  
    FixtureDef fixtureDef = new FixtureDef();  
    fixtureDef.shape = dynamicCircle;  
    fixtureDef.density = 0.5f;  
    fixtureDef.friction = 0.5f;  
    fixtureDef.restitution = 0.8f;  
    body.createFixture(fixtureDef); 
    body.setLinearVelocity(0,-100);

    //slime boy
    BodyDef bodyBoxDef = new BodyDef();  
    bodyBoxDef.type = BodyType.DynamicBody;  
    bodyBoxDef.position.set(new Vector2(camera.viewportWidth * .08f,camera.viewportHeight * .191f));  
    bodyBox = world.createBody(bodyBoxDef);  
    PolygonShape slimeBox = new PolygonShape();  
    slimeBox.setAsBox(camera.viewportWidth * .04f, camera.viewportHeight * .03f);
    FixtureDef fixtureSlimeDef = new FixtureDef();  
    fixtureSlimeDef.shape = slimeBox;  
    fixtureSlimeDef.density = 1.0f;  
    fixtureSlimeDef.friction = 0.0f;  
    fixtureSlimeDef.restitution = 0.0f;  
    bodyBox.createFixture(fixtureSlimeDef);  

    debugRenderer = new Box2DDebugRenderer(); 

    body.applyTorque(1000000000);
    bodyBox.setFixedRotation(true);
    bodyBox.setBullet(true);

有人建议加快这方面的所有动作吗?

我一直在使用屏幕1280乘720但我从其他来源看到更小更好所以我缩小到640乘260但仍然不是我想要的表现。我应该去多小?

1 个答案:

答案 0 :(得分:6)

来自Box2d Manual(第2.2节):

  

Box2D针对米,千克和秒进行调整。所以你可以考虑一下   范围以米为单位。 Box2D通常在物体时效果最佳   是典型的现实世界对象的大小。例如,桶是   大约1米高。由于浮点的限制   算术,使用Box2D模拟冰川或尘埃的运动   粒子不是一个好主意。

请参阅https://stackoverflow.com/a/4556714/960524