Is then modelToWorld returning correct heights when over buildings?
You may also try this other working way:
private ["_unit", "_obj", "_ds", "_max", "_offset", "_dvec", "_mpos", "_wpos", "_gl_north", "_breakflag", "_i", "_min"];
_ds = 0.50;
_max = 1000;
_min = 20;
_offset = 1;
_unit = _this select 0;
if (count _this > 1) then {_obj = _this select 1;};
_dvec = _unit weaponDirection "BINOCULAR";
_wpos = [];
_gl_north = "LOGIC" createVehicleLocal [0,0,0];
_sea = "EmptyDetector" createVehicleLocal [0,0,0];
_sea setPosASL [getPos _unit select 0, getPos _unit select 1, 0];
_mpos = [getPos _unit select 0, getPos _unit select 1, _sea distance _unit];;
_breakflag = TRUE;
for [{_i = (_min + _ds)},{_i <= _max && _breakflag},{_i = _i + _ds}] do
{
_wpos = [(_mpos select 0)+_i * (_dvec select 0), (_mpos select 1)+_i * (_dvec select 1), (_mpos select 2)+_i * (_dvec select 2) + _offset];
_gl_north setPosASL _wpos;
if ((getPos _gl_north select 2) <= 0.1) then {_breakflag = FALSE;};
};
deleteVehicle _gl_north;
deleteVehicle _sea;
if (!_breakflag) then
{
if (isnil "_obj") then
{
_wpos
}
else
{
_obj setPos _wpos;
TRUE
};
};