util.TraceLine

From Garry's Mod
Jump to: navigation, search
 util.TraceLine( )

Contents

Description

Performs a trace with the given trace data.

NOTE

Clientside entities will not be hit by traces.

Arguments

table TraceData

The trace data to use. See Trace structure

Returns

table

Trace result. See TraceResult structure.

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.

Examples

Example

Using a function callback as filter.

local tr = util.TraceLine( {
	start = LocalPlayer():EyePos(),
	endpos = LocalPlayer():EyePos() + EyeAngles():Forward() * 10000,
	filter = function( ent ) if ( ent:GetClass() == "prop_physics" ) then return true end end
} )

print( tr.HitPos, tr.Entity )

Output:

The trace will only hit prop_physics or world.
Personal tools
Navigation