util/TraceEntity

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Created page with "{{Func |Name=TraceEntity |Parent=util |Description=Runs a trace using the ent's collisionmodel between two points, returning a {{Struct| TraceRes}} |Realm=Shared |IsClass...")
 
m (This trace does not rotate)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=TraceEntity
+
|Description=Runs a trace using the entity's collisionmodel between two points. This does not take the entity's angles into account and will trace its unrotated collisionmodel.
|Parent=util
+
 
|Description=Runs a trace using the ent's collisionmodel between two points, returning a {{Struct| TraceRes}}
+
{{Note|Clientside entities will not be hit by traces.}}
 
|Realm=Shared
 
|Realm=Shared
 
|IsClass=No
 
|IsClass=No
 +
}}
 +
{{Arg
 +
|type=table
 +
|name=tracedata
 +
|desc=Trace data. See {{Struct|Trace}}
 
}}
 
}}
 
{{Arg
 
{{Arg
Line 10: Line 15:
 
|name=ent
 
|name=ent
 
|desc=The entity to use
 
|desc=The entity to use
}}
 
{{Arg
 
|type=table
 
|name=tracedata
 
|desc=The {{Struct| Trace}}
 
 
}}
 
}}
 
{{Ret
 
{{Ret
 
|type=table
 
|type=table
|desc= traceRes
+
|desc=Trace result. See {{Struct|TraceResult}}
 
}}
 
}}
 
{{Example
 
{{Example
| Description = From sandbox/gamemode/prop_tools.lua, this checks if there are any entities inside our entity
+
|Description=From sandbox/gamemode/prop_tools.lua, this checks if there are any entities inside our entity
| Code = local trace = { start = ent:GetPos(), endpos = ent:GetPos(), filter = ent }
+
|Code=local trace = { start = ent:GetPos(), endpos = ent:GetPos(), filter = ent }
 
local tr = util.TraceEntity( trace, ent )  
 
local tr = util.TraceEntity( trace, ent )  
 
if ( tr.Hit ) then
 
if ( tr.Hit ) then
  ...
+
  -- Do stuff
 +
end
 
}}
 
}}

Latest revision as of 15:10, 31 July 2018

 util.TraceEntity( )

Contents

Description

Runs a trace using the entity's collisionmodel between two points. This does not take the entity's angles into account and will trace its unrotated collisionmodel.

NOTE

Clientside entities will not be hit by traces.

Arguments

table tracedata

Trace data. See Trace structure

Arguments

Entity ent

The entity to use

Returns

table

Trace result. See TraceResult structure

Examples

Example

From sandbox/gamemode/prop_tools.lua, this checks if there are any entities inside our entity

local trace = { start = ent:GetPos(), endpos = ent:GetPos(), filter = ent }
local tr = util.TraceEntity( trace, ent ) 
if ( tr.Hit ) then
 -- Do stuff
end


Personal tools
Navigation