Is there a way to transform location for only the z-axis?

I put in the line trace and thanks for the explanation as it was very easy to understand. It works perfectly a few times, but then for some reason it stops working after a few times and my character gets stuck in the floor.