Garry's Mod Wiki


  table ents.FindAlongRay( Vector start, Vector end, Vector mins = nil, Vector maxs = nil )


Returns a table of all entities along the ray. The ray does not stop on collisions, meaning it will go through walls/entities.

This function is capable of detecting clientside only entities.

This internally uses a Spatial Partition to avoid looping through all entities.


1 Vector start
The start position of the ray
2 Vector end
The end position of the ray
3 Vector mins = nil
The mins corner of the ray
4 Vector maxs = nil
The maxs corner of the ray


1 table
Table of the found entities. There's a limit of 1024 entities.


Example usage of this function, as a "trace" of sorts.

concommand.Add( "test_trace", function( ply ) local plyTr = ply:GetEyeTrace() local ents = ents.FindAlongRay( plyTr.StartPos, plyTr.HitPos ) PrintTable(ents) end )