Dota 2 Workshop Tools/Scripting/API/Global.TraceLine
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
Note: This page was previously automatically generated. Any changes may be overwritten
Function Description
bool TraceLine(table parameters)
Does a raytrace along a line specified by two vectors, returning the first entity or geometry hit along the way. Script version of UTIL_TraceLine().
- Example
-- Traces a line 100 units forward from the postion of the player
-- If the trace hits, a line is drawn to the hit position.
local playerEnt = Entities:FindByClassname(nil, "player")
local startVector = playerEnt:GetCenter()
local traceTable =
{
startpos = startVector;
endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0));
ignore = playerEnt;
mask = 33636363 -- TRACE_MASK_PLAYER_SOLID from L4D2 script API, may not be correct for Source 2.
}
TraceLine(traceTable)
if traceTable.hit
then
DebugDrawLine(traceTable.startpos, traceTable.pos, 0, 255, 0, false, 1)
DebugDrawLine(traceTable.pos, traceTable.pos + traceTable.normal * 10, 0, 0, 255, false, 1)
else
DebugDrawLine(traceTable.startpos, traceTable.endpos, 255, 0, 0, false, 1)
end
Parameters
Type | Name | Description |
---|---|---|
table | parameters | 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.
Input Parameters
Passed to the parameters table to set up the trace.
Type | Name | Description |
---|---|---|
Vector | startpos | Global vector where to start the trace. |
Vector | endpos | Global vector where to end the trace. |
int | mask | Collision type bitmask. |
CBaseEntity | ignore | 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 for nil before using.
Type | Name | Description |
---|---|---|
Vector | pos | Global 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 set to nil if it is false
|
Vector | normal | World space normal vector of the surface hit. |