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

From Valve Developer Community
Jump to: navigation, search
Note: This page was previously automatically generated. Any changes may be overwritten

Function Description

bool TraceHull(table parameters)

Traces a bounding box along a line. The bounding box center follows the line.


Example
-- Traces a line 100 units forward from the postion of the player, using the players bounding box.
-- 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.
	min = playerEnt:GetBoundingMins();
	max = playerEnt:GetBoundingMaxs()
}
 
TraceHull(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.
Vector min Minimum extents of the bounding box.
Vector max Maximum extents of the bounding box.
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 along the line where the bounding box 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.