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 moveandslide's up direction to Vector3.UP and I even made a print("player is on ground") to check if isonfloor is true. Each time I check it says that isonfloor 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 physicsprocess(delta) function

Godot version v3.4-stable
in Engine