Kinematicbody's collisionshape pushed into the floor when is_on_floor()

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

I made a kinematicbody that has a capsule collision shape and capsule mesh. I’m trying to apply gravity to it and I succeeded somewhat. The problem is that the capsule slightly sinks into the floor.

I’ve set move_and_slide’s up direction to Vector3.UP and I even made a print(“player is on ground”) to check if is_on_floor is true. Each time I check it says that is_on_floor is true. So it knows it is on the ground, but sinks into it!

my 3dmovement function which has the downward force is:

func movement_handler(delta):
var direction = Vector3()
if Input.is_action_pressed("move_right") and Input.is_action_pressed("move_left"):
	direction.x = 0
elif Input.is_action_pressed("move_right"):
	direction += transform.basis.x
elif Input.is_action_pressed("move_left"):
	direction -= transform.basis.x

if Input.is_action_pressed("move_forward") and Input.is_action_pressed("move_backward"):
	direction = 0
elif Input.is_action_pressed("move_backward"):
	direction += transform.basis.z
elif Input.is_action_pressed("move_forward"):
	direction -= transform.basis.z

if Input.is_action_pressed("sprint"):
	direction = direction.normalized() * run_speed
else:
	direction = direction.normalized() * walk_speed

if is_on_floor():
	direction.y = -0.01
else:
	direction.y -= gravity

if Input.is_key_pressed(KEY_H) and is_on_floor():
	print("Player is on the ground.")

move_and_slide(direction, Vector3.UP)

and I call this function in the _physics_process(delta) function

:bust_in_silhouette: Reply From: Inces

Perhaps Your player is not on_floor every few frames in process() and it is enough to make him be pressed below ground with gravity. You will not see it by printing in process(), You could eventually print in the line where gravity is applied - how often that happens when player is idle.

Anyhow, You are forcing body on the ground with code. Is there any reason You can’t make it collide with the floor ?