Dota 2 Workshop Tools/Scripting/API/Global.TraceHull: Difference between revisions
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
RoyAwesome (talk | contribs) (Dota_Lebot push: Updated Page) |
(Added documentation and example) |
||
| Line 1: | Line 1: | ||
{{Note | This page | {{Note | This page was previously automatically generated. Any changes may be overwritten}} | ||
[[Category:Dota2Function]] | [[Category:Dota2Function]] | ||
[[Category:Global]] | [[Category:Global]] | ||
| Line 6: | Line 6: | ||
''' bool TraceHull( | ''' bool TraceHull(table ''parameters'') ''' | ||
Traces a bounding box along a line. The bounding box center follows the line. | |||
;Example | |||
<source lang="lua"> | |||
-- 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) | |||
else | |||
DebugDrawLine(traceTable.startpos, traceTable.endpos, 255, 0, 0, false, 1) | |||
end | |||
</source> | |||
== Parameters == | == Parameters == | ||
| Line 18: | Line 44: | ||
! 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. | |||
|- | |||
| 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.}} | |||
{| class="standard-table" style="width: 50%;" | |||
! 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}} | |||
|} | |||
Revision as of 11:56, 18 January 2017
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)
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.
| 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. |