When I jump on a 2d game the character doesnt come back down and just slides to infinity

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zizico2
export var player_speed = 900
export var jumpforce = 200
export var acceleration = 5

var raycast_down = null

var current_speed = 0

var btn_right
var btn_left
var btn_jump

func move(speed, acc, delta):
	current_speed = lerp(current_speed , speed, acc * delta)
	linear_velocity.x = current_speed

func is_on_ground():
	if raycast_down.is_colliding():
		return true
		return false

func _ready():
	raycast_down = get_node("RayCast2D")

func _process(delta):

	btn_left = Input.is_action_pressed("ui_left")
	btn_right = Input.is_action_pressed("ui_right")	
	btn_jump = Input.is_action_just_pressed("ui_jump")

	if btn_left:
		move(-player_speed, acceleration, delta)
	elif btn_right:
		move(player_speed, acceleration, delta)
		move(0, acceleration, delta)
	if is_on_ground():
		if btn_jump:
			linear_velocity.y = jumpforce

Here’s my code. Idk what’s wrong. And another question. I’m teasting this in a floating platform so I can still test gravity just by walking out of the platform. And no matter how mutch i increase mass and gravity scale the character always falls down at the same speed. ?!?!

Thanks in advance.

:bust_in_silhouette: Reply From: Bartosz

You need to apply gravity to make it accelerate downward.

In your code is see only one place where you modify y component of linear_veloctiy

 if is_on_ground():
    if btn_jump:
        linear_velocity.y = jumpforce # <-- here

As a side note you may try using functionality of KinematicBody2D or RigidBody2D to move objects.