I assume that you are calling update()
once every frame, before you draw the frame.
Your problem is that you are doing either the collision correction beforeor the movement every frame. You need to do both. What's happening is:
- Your character checks if it is below the screen bounds, it isn't
- So it moves below the screen bounds, draws for one frame below the screen bounds
- Then, on the next frame checks again if it is below the screen bounds, it is, so it corrects itself
Try this
public void update(float dt) {
//Let the player intially move wherever they want
velocity.add(0, GRAVITY, 0);
velocity.scl(dt);
location.add(MOVEMENT * dt, velocity.y, 0);
velocity.scl(1 / dt);
//If they ended up below the screen, move them up and cancel out gravity
if (location.y < screenBounds.y) {
velocity.y = 0;
location.y = screenBounds.y;
}
}
Also, you probably don't need the scl()
calls. Instead, just multiply the y velocity by dt
location.add(MOVEMENT * dt, velocity.y * dt, 0);