Left 4 Dead 2/Scripting/Script Functions/TraceLine
< Left 4 Dead 2 | Scripting | Script Functions
Jump to navigation
Jump to search
Function Description
bool TraceLine(table traceTable)
Does a raycast along a line specified by two vectors, returning the first entity or geometry hit along the way. Script version of UTIL_TraceLine().
Parameters
Type | Name | Description |
---|---|---|
table | traceTable | Table used for both input and output. |
Returns
bool - Whether the trace is successful. This only indicates that the trace was done, not whether it hit anything.
Example
traceTable <-
{
start = Vector( 0,0,0 )
end = Vector( 0,0,256 )
}
if(TraceLine(traceTable))
{
if(traceTable.hit)
{
printl("Trace hit!")
}
else
{
printl("Trace missed!")
}
}
else
{
printl("Trace failed!")
}
Input Parameters
Passed to the parameters table to set up the trace. The only required information to make the trace is providing the start and end point.
Type | Name | Description |
---|---|---|
Vector | start | Global vector where to start the trace. |
Vector | end | Global vector where to end the trace. |
int | mask | Optional collision type bitmask. Masks: TRACE_MASK_VISIBLE_AND_NPCS (default), TRACE_MASK_ALL, TRACE_MASK_VISION, TRACE_MASK_SHOT, TRACE_MASK_PLAYER_SOLID, |
CBaseEntity | ignore | Optional entity to ignore when tracing. |
Output parameters
Output written by the function to the parameters table.
Note: These parameters may not exist if the trace does not hit. Check that the key exists before using.
Type | Name | Description |
---|---|---|
Vector | pos | World space vector where the trace hit. |
float | fraction | Fraction from the start to end where the trace hit. |
bool | hit | Whether the trace hit something. Always present. |
CBaseEntity | enthit | Handle of the entity the trace hit. |
bool | startsolid | Whether the trace started inside something. Note: This parameter is not set if it is false
|