How to get player Y velocity when on ground

Godot Version

4.2.1 Stable


func physics_update(delta):

	if PLAYER.is_on_floor():
		var VelocityYBefore = snapped(PLAYER.position.y, 0.01)
		await get_tree().physics_frame
		await get_tree().physics_frame
		var VelocityYAfter = snapped(PLAYER.position.y, 0.01)
		if VelocityYBefore > VelocityYAfter and PLAYER.velocity.length() < 10:
			PLAYER.velocity.x = lerp(PLAYER.velocity.x, PLAYER.velocity.x * (delta * 65), ACCELERATION)
			PLAYER.velocity.z = lerp(PLAYER.velocity.z, PLAYER.velocity.z * (delta * 65), ACCELERATION)
			PLAYER.velocity.x = lerp(PLAYER.velocity.x, 0.0, DECELERATION)
			PLAYER.velocity.z = lerp(PLAYER.velocity.z, 0.0, DECELERATION)

I know my code is very inefficient but i cant find any other way of checking if my character is going down a slope while sliding. Is there some sort of way for me to get characters up and down velocity even when on ground or is this really the only way of going about this?

EDIT: My lerps are also a little messy rn but that’s not the problem atm