Garry's Mod Wiki


table util.GetPlayerTrace( Player ply, Vector dir = ply:GetAimVector() )


Utility function to quickly generate a trace table that starts at the players view position, and ends 32768 units along a specified direction.


1 Player ply
The player the trace should be based on
2 Vector dir = ply:GetAimVector()
The direction of the trace


1 table
The trace data. See Structures/Trace


Prints the entity's model the local player is looking at to console

local tr = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) ) if IsValid(tr.Entity) then print("I saw a " end local trground = util.TraceLine( util.GetPlayerTrace( LocalPlayer(), Vector(0,0,-1) ) ) if IsValid(trground.Entity) then print("I'm standing on a "..trground.Entity:GetModel()) end

Page Links

Special Pages



Render Time: 39ms

DB GetPage 5
Generate Html 11
SaveChanges (1) 11
Render Body 0
Render Sidebar 10