0 votes

When sitting on the tiles, my character's isonfloor() switches between true and false every frame. Does anyone know what is causing this and how to fix it? If you need my code just tell me and I can give it to you. Thanks

Godot version 3.2.1
in Engine by (570 points)

Can you give the code?

Most common reason why this happen is because of floor itself. Your floor is not flatten enough that your kinematic body treat it as air etc. Try resetting the rotation of your floor and go back here

   extends KinematicBody2D

onready var jump_buffer_timer : Timer = $JumpBufferTimer
onready var anim : AnimationPlayer = $AnimationPlayer
onready var sprite : Sprite = $Sprite
onready var coyote_timer : Timer = $CoyoteTimer

const ACCELERATION : int = 512
const MAX_SPEED : int = 58
const FRICTION : float = 0.25
const AIR_RESISTANCE : float = 0.2
const GRAVITY : int = 350
const JUMP_FORCE : int = 100

var motion : Vector2 = Vector2.ZERO

var jump_buffer : bool = false
var hit_ground : bool = false
var coyote_time : bool = false

func _physics_process(delta : float) -> void:
    var x_input : float = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    if x_input != 0:
        motion.x += x_input * ACCELERATION * delta
        motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
    motion.y += GRAVITY * delta
    if is_on_floor():
        coyote_time = true
        if x_input == 0:
            motion.x = lerp(motion.x, 0, FRICTION)
        if jump_buffer == true:
            motion.y = -JUMP_FORCE
        if hit_ground == false:
            hit_ground = true
            sprite.scale = Vector2(1.6, 0.4)
        hit_ground = false
        if motion.y > 0:
        if x_input == 0:
            motion.x = lerp(motion.x, 0, AIR_RESISTANCE)
        if coyote_timer.is_stopped() == true:
    if Input.is_action_just_pressed("ui_jump"):
        if coyote_time == true:
            motion.y = -JUMP_FORCE
            jump_buffer = true
    if Input.is_action_just_released("ui_jump") && motion.y < 0:
        motion.y *= 0.6
    sprite.scale = lerp(sprite.scale, Vector2(1, 1), 0.2)
    motion = move_and_slide(motion, Vector2.UP)

func _on_JumpBufferTimer_timeout():
    jump_buffer = false

func _on_CoyoteTimer_timeout():
    coyote_time = false

I check the floor and everything is working there it seems.

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.