Player Stuck On Ground

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

Whenever my player character lands on the floor, they cannot move. (is_on_floor always comes back false for some reason) Heres my player’s script:

extends KinematicBody

#Initializes Variables
var velocity = Vector3(0,0,0)
const speed = 1
var acc = 1
var gravity = 0.01

#Handels Player Physics
func _physics_process(delta):
velocity.y -= gravity
if Input.is_key_pressed(KEY_D) and Input.is_key_pressed(KEY_A):
velocity.x = lerp(velocity.x, 0, 0.1)
elif Input.is_key_pressed(KEY_D):
velocity.x = min(velocity.x + acc, speed)
elif Input.is_key_pressed(KEY_A):
velocity.x = max(velocity.x + -acc, -speed)
else:
velocity.x = lerp(velocity.x, 0, 0.1)
move_and_slide(velocity, Vector3.UP)

Any Ideas?

:bust_in_silhouette: Reply From: SQBX

Change velocity.y -= gravity to velocity.y -= 0 if is_on_floor() else gravity

Also, you should use Input.is_action_pressed rather than Input.is_key_pressed

Look into lerping as well; it is usually better than using min/max