User Tools

Site Tools


4rpl:commands:getterrainlos

Index

GetTerrainLOS

GetTerrainLOS(<-startPos <-endPos <-checkLastCell) ->hitPos

Description

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.

:NOTE:
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)).

:WARNING:
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.

:NOTE:
This API has its limits. It can not detect a hit at extreme angles2).

Examples

V3(0 2 0) ->start
V3(20 2 0) ->end
GetTerrainLOS(<-start <-end) ->hit

Index

1)
Any position with an X position between (10.000-11.000] and Z position between (15.000-16.000] would be within this cell.
Example positions in cell 10,15: (10.000001,16), (10.2,15.000001), (10.6,15.3).
Please note the bounds. An X position of 15.00000 is NOT within ANY cell located at (15,Z). 15.00000 is located within cell (14,Z) instead.
2)
[Tested] Such as from (-852 500 30) to (171 3 32). End position is behind a wall and a hit is detected should the starting X pos be greater than -851 but fails otherwise (no other changes than starting X).
4rpl/commands/getterrainlos.txt · Last modified: 2024/04/13 14:27 by durikkan