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 maxspeed = 64
var gravity = 200
const friction = 0.25
var jumpforce = 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 physicsprocess(delta):
motion = moveandslide(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 isonfloor() == true:
print("on floor")
if isonceiling() == true:
print("on ceiling")
if ison_wall() == true:
print("on wall")