util.TraceLine

From GMod Wiki

Jump to: navigation, search
Function
Syntax util.TraceLine( Trace TraceData )
Where is this used?
Description:
The engine will test for objects that block the path of an imaginary point moving in a straight line from StartPos to EndPos, and will return information about said collisions. This is referred to as a trace.
Returns: traceres TraceResult
Part of Library: Util
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Util.TraceLine]Util.TraceLine [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionTrace 80 units forward of a players view.
Used onNewerShared.png
Code
 
local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector()
local tracedata = {}
tracedata.start = pos
tracedata.endpos = pos+(ang*80)
tracedata.filter = self.Owner
local trace = util.TraceLine(tracedata)
if trace.HitNonWorld then
   target = trace.Entity
   --make it splode or something
end
 
OutputN/A

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox