Have you looked at the 2D platform demo? The way you are implementing character movement is not very good.
The first problem looks like it happened due to the fact that once you press up, you keep applying the jump height velocity. Causing it to pretty much "fall up" until it hits a floor.
The second problem is so because you're character is not adding velocity. It is setting it.
Both of these problems, plus others that may arise along the way can be solved by storing a velocity variable.
var linear_velocity = Vector2(). And use this with
move_and_slide instead. If you want to apply forces to your character, like jump for instance, you add that force to
linear_velocity and it gets taking care of by
So here's how it should work.
#the following code is inside physics_process. Note that linear_velocity was defined outside of this function.
direction = MoveDirection.NONE
#First we add gravity to the velocity.
linear_velocity.y += GRAVITY
#Apply horizontal friction. So that the character doesn't slide forever.
linear_velocity.x *= 0.0
#We then check if the player wants to move left or right.
#And if so, add a horizontal force to linear_velocity.
linear_velocity.x -= MOVE_SPEED
direction = MoveDirection.LEFT
linear_velocity.x += MOVE_SPEED
direction = MoveDirection.RIGHT
#Check if you can and should jump.
if is_on_floor() and Input.is_action_just_pressed("ui_up"):
#And if so, add a vertical force going up.
linear_velocity.y -= JUMP_SPEED
if not is_on_floor():
direction = MoveDirection.UP
#The most important step. Setting linear_velocity to the result of move_and_slide.
linear_velocity = move_and_slide(linear_velocity, Vector2(0, -1))
#Change animation according to direction.
Please read the comments if you want to understand what's going on.