how to stop "hopping" off sloped ledges when moving off them?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JoltJab

(in Godot 4.0.beta2)

So I’ve got some basic movement made, but I’m noticing a problem when my player (CharacterBody2D) walks off a sloped ledge. It looks like a hop, but I’m pretty sure it’s just that the vertical movement isn’t included in the velocity vector.

How do I keep my player’s (CharacterBody2D) vertical movement when going off sloped ledges?

enter image description here

-Code when on ground-

func ground(delta: float) -> void:
    #--inputs--#
    input_direction.x = Input.get_axis("Terra_Left","Terra_Right"); #left and right arrows
    input_direction.y = -int(Input.is_action_just_pressed("Terra_Jump")); #space bar

    #--physics and code stuff--#
    velocity.x = round(speed) * input_direction.x;
    velocity.y = jumpPower * input_direction.y;

    move_and_slide();

    #--sprite info--#
    sprTerra.rotation = lerp(sprTerra.rotation,Vector2.UP.angle_to(get_floor_normal()),0.3);


    #changing state
    if (!is_on_floor()):
        changeState(state.air); #you are now in the air and not on the ground

-Code when in air-

func air(delta: float) -> void:
    #--inputs--#	
    input_direction.y = -int(Input.is_action_just_pressed("Terra_Jump"));
    var jumpHold: bool = Input.is_action_pressed("Terra_Jump");
    var jumpReleased: bool = Input.is_action_just_released("Terra_Jump");

    #--physics and code stuff--#
    add_gravity(delta);
    #if let go of jump, add extra gravity to pull down player	
    if jumpsLeft && -input_direction.y>0:
        velocity.y = jumpPower * input_direction.y;

    if jumpReleased:
        jumpsLeft = max(0,jumpsLeft-1);
    if (!jumpHold && velocity.y<0):	#if not holding jump button and moving up	
        velocity+= (GLOBAL.grav*2*delta);

    move_and_slide();

#--sprite info--#
#rotation
    sprTerra.rotation = lerp(sprTerra.rotation,0.0,0.07);


#changing state
    if (is_on_floor()):
        jumpsLeft=MaxjumpCount;
        changeState(state.ground);
:bust_in_silhouette: Reply From: JoltJab

Never mind, I got it. Ended up adding the velocity.y when going up and down slopes, and had to check for collisions a little oddly but it’s workin.