플레이어가 점프 할 때 나는 어떤 상수로 속도를 설정 한 다음 중력 * deltaTime에 의해 시간에 따라 상수를 감소시킵니다. 그러나 어떤 이유로이 점프 높이가 달라집니다. deltaTime을 메인 게임 루프의 상수로 대체하면이 문제가 사라지기 때문에 deltaTime과 관련이 있다고 생각합니다.libGDX 가변 높이 점프
다음은 revelvent 코드입니다.
GameState
public void resolveInput(float deltaTime) {
if(Gdx.input.isKeyJustPressed(Keys.ESCAPE))
Gdx.app.exit(); //temporary until we build menus
player.velocity.x = 0;
if(Gdx.input.isKeyPressed(Keys.A)) {
player.velocity.x -= Constants.PLAYER_MOVE_SPEED * deltaTime;
player.right = false;
}
if(Gdx.input.isKeyPressed(Keys.D)) {
player.velocity.x += Constants.PLAYER_MOVE_SPEED * deltaTime;
player.right = true;
}
if(Gdx.input.isKeyPressed(Keys.SPACE) && !player.falling) {
player.velocity.y = Constants.PLAYER_JUMP_SPEED;
player.falling = true;
}
}
public void update(float deltaTime) {
resolveInput(deltaTime);
world.update(deltaTime);
camHelper.update(deltaTime);
}
세계 :
public void update(float deltaTime) {
player.update(deltaTime);
player.setPosition(resolveCollisions());
}
public Vector2 resolveCollisions() {
Rectangle p = player.getBoundingRectangle();
//The rest of the code doesn't get called in my test cases so I won't put it in here...
return new Vector2(p.x + player.velocity.x, p.y + player.velocity.y);
}//resolveCollisions
플레이어 :
public void update(float deltaTime) {
if(velocity.len() == 0)
sTime = 0;
else
sTime += deltaTime;
if(falling)
velocity.y -= Constants.GRAVITY * deltaTime;
velocity.y = MathUtils.clamp(velocity.y, -Constants.PLAYER_MAX_SPEED, Constants.PLAYER_MAX_SPEED);
}
어떤 도움이 많이 주시면 감사하겠습니다 : 플레이어가 있지 않으면 플랫 포머가 잘 작동하지 않습니다 항상 같은 높이로 뛰어!
내가 알고있는 한 바로 그 순간이 바로 그 순간입니다. 플레이어가 점프하면 y 속도가 설정되고 플레이어가 중력을 업데이트 할 때마다 * deltaTime이 y 속도에서 뺍니다. 그래도 도움을 주셔서 감사합니다! – Calvin