um well, assuming you already know how to call the locz function, you can set the units flying height to say 50 assuming it is about the right height for a projectile to begin its travel. Then you simply just have the height change by 50 - z height. If the z height is greater than the 50, then it hits the ground and u remove it. I think it should work both ways, if the origin of the missile is on a flat surface of 0 height and the missle hight is 50, then it will stay at 50 until say a bump of approximately 20 height arrives, then it will set the new missle height to 50 - 20 = 30 new height is 30. Say it shoots over a canyon, and the button of the canyon is -500. Then it will make the height 50 -(-500) = 550 so it stays the same height. This is just out of my head so it should work but might need some tweaking. Test it out and let me know how it works, that is if this is what you are wanting.
EDIT- You may have to make an initial Z height of the origin of the missiles start location. Meaning you will need to save the variable and subtract it from the next LocZ's location. So if a missle starts at a Z height of say 250, and it passes over a canyon of -500, you will have to set the height to 50, but then do Next LocZ - 250. So when the missile starts, a few feet in front say the hill slopes down slightly before the canyon, it will set the height to 50 height - (new locZ(225) - 250) = 50 -(-25) = 75, so it will retain its height. The lower the elevation from the missiles origin, the higher the flying units height will be set. So when the canyon arrives, it will be 50 - (-500 - 250) = 50 - -750 = 800, so the height will now be 800, yet again retaining its flat trajectory. Again, I havent tested it ingame, but this concept should work.