Garry's Mod Wiki

Garry's Mod Wiki

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

Description

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

For usage with util.TraceLine and similar functions.

Arguments

1 Player ply
The player the trace should be based on
2 Vector dir = ply:GetAimVector()
The direction of the trace. By default falls back to the direction the player is looking in.

Returns

1 table
The trace data. See Trace structure

Example

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 "..tr.Entity:GetModel()) 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

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...