Dota 2 Workshop Tools/Scripting/API/Global.TraceLine: Difference between revisions
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
RoyAwesome (talk | contribs) (Dota_Lebot push: Updated Page) |
m (Added undocumented normal parameter.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Note | This page | {{Note | This page was previously automatically generated. Any changes may be overwritten}} | ||
[[Category:Dota2Function]] | |||
[[Category:Global]] | |||
== Function Description == | == 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|UTIL_TraceLine()]]. | |||
;Example | |||
<source lang="lua"> | |||
-- 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 | |||
</source> | |||
== Parameters == | == Parameters == | ||
Line 16: | Line 40: | ||
! Description | ! Description | ||
|- | |- | ||
| | | table | ||
| | | parameters | ||
| | | Table used for both input and output. | ||
|} | |} | ||
== Returns == | == Returns == | ||
''bool'' - | ''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. | |||
{| class="standard-table" style="width: 50%;" | |||
! 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.}} | |||
{| class="standard-table" style="width: 50%;" | |||
! 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. | |||
|} |
Latest revision as of 15:11, 22 January 2017

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.

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. ![]() |
Vector | normal | World space normal vector of the surface hit. |