While you're attempting to account for gravity here:
velocity.y += gravity * delta
That adjusted value is never used for anything. Normally, you'd calculate velocity and then pass it into move_and_slide()
as the first argument. Additionally, you'd store the return value from that call back in velocity
.
A typical call would look like this:
velocity = move_and_slide(velocity, Vector2.UP)
Also note, as documented, move_and_slide()
automatically calculates frame based movement, so you should not use delta
in the velocity argument (as your original code does).