Dota 2 Workshop Tools/Scripting/API/Global.TraceLine

From Valve Developer Community
< Dota 2 Workshop Tools‎ | Scripting‎ | API
Revision as of 15:11, 22 January 2017 by Rectus (talk | contribs) (Added undocumented normal parameter.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Note.png 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().

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


if traceTable.hit 
	DebugDrawLine(traceTable.startpos, traceTable.pos, 0, 255, 0, false, 1)
	DebugDrawLine(traceTable.pos, traceTable.pos + traceTable.normal * 10, 0, 0, 255, false, 1)
	DebugDrawLine(traceTable.startpos, traceTable.endpos, 255, 0, 0, false, 1)


Type Name Description
table parameters Table used for both input and output.


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.png 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.png Note:  This parameter is set to nil if it is false
Vector normal World space normal vector of the surface hit.