@cybereality
I also asked on Reddit and someone suggested to only apply gravity when not on the ground, and that fixed it.
After doing that however, it was jittery when on the ground and colliding with a wall, so I added when not on walls to the gravity if statement, like this:
velocity.x = int(move_toward(velocity.x, MAX_SPEED * direction, ACCELERATION * delta))
if !is_on_floor() && !is_on_wall():
velocity.y = int(move_toward(velocity.y, max_fall_speed, gravity * delta))
But now I can't jump when touching a wall on the ground, what should I do?