Why are you minusing the location from the trace start? All you want is the actual hit location and that should be your Z height. Personally I would take a trace at the end location of the square and then using the end location of the previous trace you can then set the angle of the square to match up to the terrain.