User Tools

Site Tools


4rpl:commands:getterrainlos

This is an old revision of the document!


Index

GetTerrainLOS

GetTerrainLOS(<-start <-end <-checkLastCell) ->hit

Description

Checks a line running from start to end and returns the terrain cell (if any) that the line first intersects.
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.

-The 'start', 'end' and 'hit' vars are all vectors.

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

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

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

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

Examples

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

Index

4rpl/commands/getterrainlos.1661315348.txt.gz · Last modified: 2022/08/24 00:29 by Vertu