0 votes

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 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 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 is
onfloor() == true:
print("on floor")
if is
onceiling() == true:
print("on ceiling")
if is
on_wall() == true:
print("on wall")

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

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.

by (3,048 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.