ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Client functions
  3. getWorldFromScreenPosition

Function

getWorldFromScreenPosition

ClientWorldIdentical to MTA:SA

Converts a point on the screen into a point in the 3D world at the given distance from the camera. Useful e.g. for placing objects with the mouse cursor.

Syntax

float, float, float getWorldFromScreenPosition(float x, float y, float depth)

Arguments

xfloat
X position on screen in pixels.
yfloat
Y position on screen in pixels.
depthfloat
Distance from the camera in metres.

Returns

World point x, y, z, or false.

Example

addEventHandler("onClientClick", root, function(button, state, sx, sy)
    if button == "left" and state == "down" then
        local x, y, z = getWorldFromScreenPosition(sx, sy, 10)
        if x then outputChatBox(("%.1f %.1f %.1f"):format(x, y, z)) end
    end
end)

See also