I am implementing basic gravity+floor collision but due to the speed always increasing, after I hit the floor I sink like im stood in quicksand, the issue is that if I put an 'if !grounded around the gravity calculations jumping will not work.
Any ideas?
private void gravity() {
float Y = sprite.getY();
speed += accel * Gdx.graphics.getDeltaTime();
Y += speed * Gdx.graphics.getDeltaTime();
sprite.setY(Y);
if (sprite.getY() <= floor) {
grounded = true;
speed = 0;
}
}
public void controls() {
if (Gdx.input.isKeyPressed(Keys.W) && grounded) {
grounded = false;
speed = 300;
}
}