Both sides previous revisionPrevious revisionNext revision | Previous revision |
4rpl:commands:getterrainlos [2022/08/24 01:56] – Overflow mention and applications when dealing with void. Vertu | 4rpl:commands:getterrainlos [2025/02/14 14:57] (current) – external edit 127.0.0.1 |
---|
| |
====== GetTerrainLOS ====== | ====== GetTerrainLOS ====== |
GetTerrainLOS(<-start <-end <-checkLastCell) ->hit | GetTerrainLOS(<-startPos <-endPos <-checkLastCell) ->hitPos |
| |
===== Description ===== | ===== Description ===== |
Checks a line running from start to end and returns the terrain cell (if any) that the line first intersects.\\ | 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. 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. | 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 'start', 'end' and 'hit' vars are all vectors. | -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]. |
| |
-Checking the last cell is a Boolean that will check all cells from start to end. This is potentially useful as unit positions are located just above terrain. This parameter is a good way to reduce sensitivity when having an end position being from [[GetUnitPosition]]. (If this is wrong, feel free to update this). | -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 1x1 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)((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).\\ |
-The return value is the vector position in 3d space (floats) of the location where the collision took place. If there is no collision, then the returned hit locations are negative. Please keep this in mind if wanting to place this API within an [[if]] clause. You will most likely want to run this API outside of the [[if]] clause and check if one of the vectors returns -1 instead. | 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.)). 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:\\ | :NOTE:\\ |
This API has a more applicable LOS calculation than the LOS parameter in [[GetUnits]] (at least in practice). If you are making a custom unit which depends on LOS calculations within [[GetUnits]] and it consistently fails for what ever reason to have a clear LOS in practice (such as projectiles constantly hitting into terrain), this is an EXCELENT backup to double check. | 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:\\ | :WARNING:\\ |
This API will overflow if void terrain is involved. This means the API will not return -1 in any vector but -2,147,483,648. This means you can not use eq(-1) when looking for when no terrain collision occurs if void is involved. So instead of using eq(-1), use lt0. | 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 angles(([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).)). |
| |
| |