Dota 2 Workshop Tools/Scripting/API/Global.TraceCollideable
< Dota 2 Workshop Tools | Scripting | API
Jump to navigation
Jump to search
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. |