is_on_floor is flickering between true and false

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

i am following garbaj third person controller and is on floor is 80% returns false and randomly returns true when on ground. i checked everyhting i watched the video 5 times. nothing works. help.

example of debug:

(0, -70.904762, 0)False
(0, -70.904762, 0)True
(0, -71.068092, 0)False
(0, -71.231422, 0)False

    extends KinematicBody

onready var gun_pivot: Spatial = $GunPivot
onready var pivot: Spatial = $Pivot

export var gravity = .98
export var jump = 5 
var capncrunch = Vector3()

var direction = Vector3()
var speed = 10
var velocity = Vector3()
var acceleration = 5

var mouse_sensitivity = .1

func _ready() -> void:

func _input(event: InputEvent) -> void:
	if Input.is_action_just_pressed('ui_cancel'):
	if Input.is_action_just_pressed('shoot'):
	if event is InputEventMouseMotion:
		rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
		pivot.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
		pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))
		gun_pivot.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
		gun_pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))
func _process(delta: float) -> void:
	direction = Vector3()
	if Input.is_action_pressed('move_forward'):
		direction -= transform.basis.z

	elif Input.is_action_pressed('move_backwards'):
		direction += transform.basis.z
	if Input.is_action_pressed('move_left'):
		direction -= transform.basis.x

	elif Input.is_action_pressed('move_right'):
		direction += transform.basis.x
	print(capncrunch ,is_on_floor())
	move_and_slide(capncrunch, Vector3.UP)
	direction = direction.normalized()
	velocity = direction * speed
	velocity.linear_interpolate(velocity, acceleration * delta)
	move_and_slide(velocity, Vector3.UP)
func apply_gravity(delta):
	if not is_on_floor():
		capncrunch.y -= gravity * delta

func jump():
	if Input.is_action_just_pressed('jump') and is_on_floor():
		capncrunch.y = jump
:bust_in_silhouette: Reply From: Calinou

This is a known issue. The best way to work around this is to store the result of is_on_floor() over 3 frames in an Array, then write a function that returns true if any of the values in the Array are true.

See Shifty’s Godot Character Movement Manifesto for more information.