Dota 2 Workshop Tools/Scripting/API/Global.TraceCollideable: Difference between revisions
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
RoyAwesome (talk | contribs) (Dota_Lebot push: Updated Page) |
Thunder4ik (talk | contribs) m (clean up, added deadend tag) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Note | This page | {{Dead end|date=January 2024}} | ||
{{Note | This page was previously automatically generated. Any changes may be overwritten}} | |||
== Function Description == | == Function Description == | ||
''' bool TraceCollideable(table ''parameters'') ''' | |||
''' | Does a raytrace against a single solid entity. An extra bounding box centered around the entity can be added with the ''mins'' and ''maxs'' parameters. | ||
;Example | |||
<source lang="lua"> | |||
-- Traces a line 100 units forward from the postion of the player, trying to find an entity named "my_prop". | |||
-- If the trace hits, a line is drawn to the hit position, along with the surface normal. | |||
local playerEnt = Entities:FindByClassname(nil, "player") | |||
local startVector = playerEnt:GetOrigin() + Vector(0, 0, 32) | |||
local traceTable = | |||
{ | |||
startpos = startVector; | |||
-- Traces from the player position 100 units in front of the player | |||
endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0)); | |||
ent = Entities:FindByName(nil, "my_prop"); -- Traces the entity named "my_prop" | |||
-- Adds an extra 20 x 20 x 20 bounding box on the model. | |||
mins = Vector(-10, -10, -10 ); | |||
maxs = Vector(10, 10, 10 ) | |||
} | |||
TraceCollideable(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 18: | Line 45: | ||
! 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. | |||
|- | |||
| CBaseEntity | |||
| ent | |||
| Entity to trace against. | |||
|- | |||
| Vector | |||
| mins | |||
| (Optional) Minimum coordinates of the bounding box. Local to the entity. | |||
|- | |||
| Vector | |||
| maxs | |||
| (Optional) Maximum coordinates of the bounding box. Local to the entity. | |||
|} | |||
== 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. | |||
|- | |||
| bool | |||
| startsolid | |||
| Whether the trace started inside the entity. {{Note | This parameter is set to nil if it is false}} | |||
|- | |||
| Vector | |||
| normal | |||
| Global normal vector of the surface hit. | |||
|} | |||
[[Category:Dota2Function]] | |||
[[Category:Global]] |
Latest revision as of 09:59, 21 January 2024

This article has no
links to other VDC articles. Please help improve this article by adding links
that are relevant to the context within the existing text.
January 2024


January 2024

Function Description
bool TraceCollideable(table parameters)
Does a raytrace against a single solid entity. An extra bounding box centered around the entity can be added with the mins and maxs parameters.
- Example
-- Traces a line 100 units forward from the postion of the player, trying to find an entity named "my_prop".
-- If the trace hits, a line is drawn to the hit position, along with the surface normal.
local playerEnt = Entities:FindByClassname(nil, "player")
local startVector = playerEnt:GetOrigin() + Vector(0, 0, 32)
local traceTable =
{
startpos = startVector;
-- Traces from the player position 100 units in front of the player
endpos = startVector + RotatePosition(Vector(0,0,0), playerEnt:GetAngles(), Vector(100, 0, 0));
ent = Entities:FindByName(nil, "my_prop"); -- Traces the entity named "my_prop"
-- Adds an extra 20 x 20 x 20 bounding box on the model.
mins = Vector(-10, -10, -10 );
maxs = Vector(10, 10, 10 )
}
TraceCollideable(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. |
CBaseEntity | ent | Entity to trace against. |
Vector | mins | (Optional) Minimum coordinates of the bounding box. Local to the entity. |
Vector | maxs | (Optional) Maximum coordinates of the bounding box. Local to the entity. |
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. |
bool | startsolid | Whether the trace started inside the entity. ![]() |
Vector | normal | Global normal vector of the surface hit. |