⇐ Index
GetTerrainLOS(<-startPos <-endPos <-checkLastCell) ->hitPos
Checks a line running from startPos to endPos and returns the world position (if any) where the line first ever intersects terrain geometry.
This routine is useful for checking the exact terrain Line Of Sight (LOS) between two points and where the LOS was blocked. If a unit wants to fire from any location in 3d space to any location in 3d space, this routine can check if there is any terrain in the way and where.
-The 'startPos ', 'endPos', and 'hitPos' vars are all vectors (V3) as floats.
-Returns the world space location of where the collision took place. If no hit occurs then the returned vector is the minimum value [-3.402823E+38, -3.402823E+38, -3.402823E+38].
-CheckLastCell is a Boolean that will have the API extend its calculations past the endPos until it exits the cell the end position is within or a hit is encountered. A cell is a 1×1 square and any location within this square is within that cell (no matter the Y position). For reference, the center location of cell 10,15 is (10.5,15.5)1). Be mindful with this when there is a very large difference in Y-axis / “height” between the two points as the calculation can only exit the cell laterally, not vertically. Should CheckLastCell be true and the line between startPos and endPos be mostly vertical, the calculated line will be noticeably extended past endPos.
Void (height of 0) acts as proper terrain (even outside the map). Should you use this API and it calculates a line that crosses through void terrain, it will detect the hit as expected (like (-50 0 -10)).
This API becomes unreliable when startPos and endPos are significantly off map and will consistently fail to detect a hit although the line does intersect the void terrain.
This API has its limits. It can not detect a hit at extreme angles2).
V3(0 2 0) ->start V3(20 2 0) ->end GetTerrainLOS(<-start <-end) ->hit
⇐ Index