# Why is_on_floor() always returns false

Attention Topic was automatically imported from the old Question2Answer platform.

Im want to make a 3D FPS game in Godot 3.4.4 and i have problems with jumping my code ↓↓↓

``````extends KinematicBody

export var speed = 11
export var accel = 5
export var gravity = 0.98
export var jump_power = 30

var velocity = Vector3()

func _physics_process(delta):

var direction = Vector3()
if Input.is_action_pressed("ui_up"):
elif Input.is_action_pressed("ui_down"):

if Input.is_action_pressed("ui_left"):
elif Input.is_action_pressed("ui_right"):

if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y += jump_power

direction = direction.normalized()

velocity = velocity.linear_interpolate(direction * speed, accel * delta)
velocity.y -= gravity

velocity = move_and_slide(velocity)
``````

if me printing is on floor()
and im reciving false, why?
P.S.:I always write velocity.y - = gravity because I read other answers and it said: “You always need to move the player a little down”

I think this might be happening because godot can’t really tell what is a floor or what is a wall or what is a ceiling. To fix this in the move and slide function after velocity add Vector3.Up. It will look like this:

``````velocity = move_and_slide(velocity, Vector3.UP)
``````

This tells godot that you are above a floor and like that it can detect wall and ceiling
If we did the opposite like Vector3.DOWN Then godot will treat the actual floor as ceiling
And the ceiling as floor

Hope this helps

Just wanted to add. I believe the colliding bodies are constantly pushing each other away that causes the is_on_floor() function to return false.
That’s why we need a constant force “gravity” to keep them together.
I hope my logic is correct.