Maybe something like this would work?
# The distance from player to camera
var distance_to_camera = get_distance()
# Clamp to a maximum distance
distance_to_camera = clamp(distance_to_camera, 0, 10)
# Subtract from the maximum, so we get a value that gets larger
# the closer the player is, rather than farther
distance_to_camera = 10 - distance_to_camera
# Adjust the camera's Y translation by the distance
$Camera.translation.y = distance_to_camera
One thing to note though is that you'll want to calculate the distance relative to the camera's position, but not the camera's height, as the distance from camera to play will change as you move the camera up and down.
I'd suggest having the camera as a child of a node and then get the distance from that node to the player. In other words, using a scene tree like this
- Camera_Holder node (script to move camera goes here!)
- Other nodes
That way, as long as the Camera_Holder
node doesn't move, you can move the camera without affecting the distance.