【发布时间】:2014-02-24 12:54:57
【问题描述】:
我的问题是,无论调整如何,我都无法实现快速移动的球。它漂浮在空气中,而不是从空气中射出。
在下面的方法中,我创建了一个半径为5 单位的球。将半径设置为0.01 不会产生结果差异。
创建后,我应用了一个比例荒谬的LinearImpulse,但球只会漂浮。
(另外,我正在使用 DebugRender。这不应该负责单位转换吗?)
Ball class
public Body createBody(float x, float y, float w, float h) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(x,y);
Body body = this.getWorld().createBody(bodyDef);
CircleShape shape = new CircleShape();
shape.setRadius(5);
shape.setPosition(new Vector2(0, 0)); // relative to body position
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = 3f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.8f;
body.createFixture(fixtureDef);
shape.dispose();
// note the massive impulse vector
body.applyLinearImpulse(new Vector2(10000, 100000), body.getWorldCenter(), true);
return body;
}
render method in Game class
@Override
public void render(){
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
debugRenderer.render(world, camera.combined);
// time step, velocityIterations, positionIterations
world.step(1/40.0f, 6, 2);
// scheduler takes care of creating game objects on the fly
}
【问题讨论】:
-
这可能是因为 Box2D 的最大速度受到更新率的限制。你有多少FPS?也许尝试类似 world.step(Gdx.graphics.getDeltaTime()) 的东西。
-
按照建议更改 world.step() 确实确实增加了经验速度。但我有一种感觉,这不是解决方案。由于我使用的是 debugrenderer,所有对象不应该自动正确缩放吗?