My is_on_floor() isn't working when i move left and right

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

extends KinematicBody2D

const UP = Vector2(0,-1)

var motion = Vector2()
var velocity = Vector2.ZERO

func _physics_process(delta):

velocity.x = 0

if (Input.is_action_pressed("ui_right")):
	velocity.x = 300
elif (Input.is_action_pressed("ui_left")):
	velocity.x = -300
velocity.y = 300

if  (Input.is_action_pressed("ui_up")):      
	velocity.y = -10000
velocity = move_and_slide(velocity)
motion = move_and_slide(motion,UP)


is_on_floor() returns true when i’m on the floor but as soon as i move left and right while still on the floor it returns false

:bust_in_silhouette: Reply From: whiteshampoo

You are calling move_and_slide twice.
You should call it only one time with UP