is_on_floor makes jump not work

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

So when I add “and is_on_floor()” it makes the jump function not work at all, but it works before I add the “is_on_floor()”, I have the floor defined with velocity = move_and_slide(velocity, Vector2.UP) so idk, any help? Here’s my code;

extends KinematicBody2D

var velocity = Vector2(0,0)

const Speed = 200
const Jumpforce = -900
const Gravity = 30

func _physics_process(delta):
	if Input.is_action_pressed("right"):
		velocity.x = Speed
	if Input.is_action_pressed("left"):
		velocity.x = -Speed
	velocity.y = velocity.y + Gravity
	if Input.is_action_just_pressed("Jump") and is_on_floor():    
		velocity.y = Jumpforce
	velocity = move_and_slide(velocity, Vector2.UP)
	velocity.x = lerp (velocity.x,0,0.2)

Are you aware that “jumpforce” is set to a negative number?

Silv-R | 2021-09-05 18:01

:bust_in_silhouette: Reply From: whiteshampoo

Remove the first move_and_slide