gui/ScreenToVector

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
m (Added opposite function)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=ScreenToVector
+
|Description=Converts the specified screen position to a direction vector local to the player's view. Opposite function is {{LibraryFunction|Vector|ToScreen}}.
|Parent=gui
+
|Description=Converts the specified screen position to a direction vector local to the player's view.
+
 
|Realm=Client
 
|Realm=Client
 
|IsClass=No
 
|IsClass=No

Revision as of 04:28, 22 March 2017

 gui.ScreenToVector( )

Contents

Description

Converts the specified screen position to a direction vector local to the player's view. Opposite function is Vector.ToScreen.

Arguments

number x

X coordinate on the screen.

Arguments

number y

Y coordinate on the screen.

Returns

Vector

Direction

Examples

Example

This will do a trace from the mouse position to the world

local tr = util.QuickTrace(LocalPlayer():GetShootPos(), gui.ScreenToVector(gui.MousePos()),LocalPlayer())
print(tr.HitPos)

Output:

The worldpos the cursor is pointing at will be printed

Examples

Example

Replacement for Player:GetAimVector

print(gui.ScreenToVector(ScrW()/2, ScrH()/2))

Output:

The player's current aimvector will be printed
Personal tools
Navigation