据我了解,这应该导致身体移动。我在课堂上有一个更新方法,但我不确定还要添加什么。我使用box2d作为libgdx的一部分。无论我到哪里,它只是说设置线速度,但它不起作用。
BodyDef bodyDef = new BodyDef();
bodyDef.position.set(new Vector2(pos.x, pos.y));
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.linearDamping = 0.0f;
bodyDef.angularDamping = 0.0f;
unitBoxBody = world.createBody(bodyDef);
PolygonShape player = new PolygonShape();
player.setAsBox(unit * xSize, unit * ySize);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = player;
fixtureDef.density = 0.0f;
fixtureDef.friction = 0.0f;
fixtureDef.restitution = 0.0f;
fixture = unitBoxBody.createFixture(fixtureDef);
player.dispose();
unitBoxBody.setLinearVelocity(10, 0);
我已经使用了许多大小值的速度而没有变化。
答案 0 :(得分:0)
你必须让自己的世界迈出一步:
将它放在render()方法中:
world.step(TIMESTEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
并定义这些变量:
private static final float TIMESTEP = 1.0f / 60.0f;
private static final int VELOCITY_ITERATIONS = 8;
private static final int POSITION_ITERATIONS = 3;