User Tools

Site Tools


4rpl:commands:getterrainlos

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
4rpl:commands:getterrainlos [2024/04/07 22:24] – [Description] Void acts as terrain for hit if LOS is crossed [note] Vertu4rpl:commands:getterrainlos [2024/04/13 14:27] (current) – [Description] durikkan
Line 3: Line 3:
  
 ====== 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 terrainThis parameter is a good way to reduce sensitivity when having an end position being from [[GetUnitPosition]]. (If this is wrongfeel 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 encounteredA 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 position between (10.000-11.000and Z position between (15.000-16.000would 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 (floatsof the location where the collision took place If there is no collisionthen the returned hit locations are negativePlease keep this in mind if wanting to place this API within an [[if]] clauseYou 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 verticallyShould 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 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 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 lte0.\\ +This API becomes unreliable when startPos and endPos are significantly off map and will consistently fail to detect hit although the line does intersect the void terrain.
-Further more, sometimes when calculating LOS to a void location (such as a unit position on top of the void), it would be wise to check if the Y vector is lte0 rather than lt0 and any other vector as in practice, the API becomes "indecisive". (If you have more information about this, feel free to edit this section).+
  
 :NOTE:\\ :NOTE:\\
-Void acts as terrain so if the start position is above the void and the end is below, a hit will be generated and the API works as expected.+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).)).
  
  
4rpl/commands/getterrainlos.1712543077.txt.gz · Last modified: 2024/04/07 22:24 by Vertu