my character is not coming down after jumping its keeps on flying, please help.

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

this is my code:

extends KinematicBody2D

const gravity = 30

export var speed = 120
export var jump_power = 650

var Floor = Vector2(0,-1)
var velocity = Vector2.ZERO
var onground = false

func _physics_process(delta):

if Input.is_action_pressed("ui_left"):
	velocity.x = -1
	$AnimatedSprite.flip_h = true
elif Input.is_action_pressed("ui_right"):
	velocity.x = 1
	$AnimatedSprite.flip_h = false
else:
	velocity.x = 0

velocity.y += gravity * delta

if Input.is_action_pressed("jump") and onground == true:
	velocity.y = -jump_power
	onground = false

if is_on_floor():
	onground = true
else:
	onground = false

velocity = velocity.normalized() * speed
velocity = move_and_slide(velocity,Floor)
:bust_in_silhouette: Reply From: exuin

The problem is that once the velocity is set to negative, it will never become positive again. You shouldn’t normalize the velocity in this case since you want your speed to change instead only being 120.