Garry's Mod Wiki


  table util.TraceLine( table TraceData )


Performs a trace with the given trace data.

Clientside entities will not be hit by traces.

When server side trace starts inside a solid, it will hit the most inner solid the beam start position is located in. Traces are triggered by change of boundary.


1 table TraceData
The trace data to use. See Structures/Trace


1 table
Trace result. See Structures/TraceResult.

Can return nil if game.GetWorld or its physics object is invalid. This will be the case for any traces done before GM:InitPostEntity is called.


Using a function callback as filter.

local tr = util.TraceLine( { start = LocalPlayer():EyePos(), endpos = LocalPlayer():EyePos() + EyeAngles():Forward() * 10000, filter = function( ent ) return ( ent:GetClass() == "prop_physics" ) end } ) print( tr.HitPos, tr.Entity )
Output: The trace will only hit prop_physics or world.