Garry's Mod Wiki

EyePos

  Vector EyePos()

Description

Returns the origin of the current render context as calculated by GM:CalcView.

This function is only reliable inside rendering hooks.

Issue Tracker: 2516

Returns

1 Vector
Camera position.

Example

Ensuring EyePos returns the correct value outside of render hooks.

local mins, maxs = Vector( -5, -5, -5 ), Vector( 5, 5, 5 ) hook.Add( "PreDrawTranslucentRenderables", "FixEyePos", function() EyePos() end ) hook.Add( "Think", "Use Eyepos outside of render function", function() local start = EyePos() local dir = gui.ScreenToVector( gui.MousePos() ) local trace = util.TraceLine({ start = start, endpos = start + ( dir * 10000 ), filter = { ply } }) debugoverlay.Box( trace.HitPos, mins, maxs ) end )
Output: Draws a white box in the world where you point the mouse to. Requires the developer convar to be set to 1.