he is_on_floor function always shows the value false

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

I started writing for a year recently and in my 2d platformer there was such a problem that the is_on floor function of my character does not see the “floor”
here is the code:

extends KinematicBody2D

const acceleration = 512
var max_speed = 64
var gravity = 200
const friction = 0.25
var jump_force = 128
const air_resistance = 0.02

var jump_count = 0
export var extrajumps = 1

onready var sprite = $MageAnemation
onready var animplay = $AnimationPlayer

var motion = Vector2.ZERO

func _physics_process(delta):
motion = move_and_slide(motion, Vector2.UP)

var x_input = Input.get_action_strength("d") - Input.get_action_strength("a")
if x_input != 0:#передвижение
	motion.x += x_input * acceleration * delta
	motion.x = clamp(motion.x, -max_speed, max_speed)
	sprite.flip_h = x_input < 0
	if is_on_floor() == true:
		animplay.play("walk")
else:
	if is_on_floor() == true:#анимация стояния на месте
		animplay.play("idle")
#кнец части скрипта с передвижением


motion.y += 2 * gravity * delta#гравитация

if is_on_floor():
	jump_force = 128
	if x_input == 0:
		motion.x = lerp(motion.x, 0, friction)

if is_on_floor() == false and jump_count == 0:
	pass#сюда вставить анимацию второго прыжка
else:
	if is_on_floor() == false:
		pass #сюда вствить анимацию первого прыжка

if jump_count == extrajumps:
	jump_force = 112

if Input.is_action_just_pressed("space") && jump_count < extrajumps and is_on_floor() == true:
	if is_on_floor() == true:
		motion.y = -jump_force
		jump_count += 1
else:
	if Input.is_action_just_released("space") and motion.y > -jump_force/2:
		motion.y = -jump_force

if x_input == 0:
	motion.x = lerp(motion.x, 0, air_resistance)







pass

func _ready():
if is_on_floor() == true:
print(“on floor”)
if is_on_ceiling() == true:
print(“on ceiling”)
if is_on_wall() == true:
print(“on wall”)

:bust_in_silhouette: Reply From: Ertain

I don’t know how I can help, but the line motion = move_and_slide(motion, Vector2.UP) may need to be moved to the end of the _physics_process() function. This is because the code you gave first uses the move_and_slide() function, and then applies edits to the motion variable that’s used in the function.