- Documentation
- Client functions
- getWorldFromScreenPosition
Function
getWorldFromScreenPosition
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
getScreenFromWorldPositionTurns a world point into a screen point (pixels). Returnsfalsewhen the point is behind the camera or off screen. The third result is the distance from the camera. Useful for text above heads.processLineOfSightFinds the first obstacle on the segment between two points and returns the hit details. On the client it asks the game (terrain, buildings, objects, cars, peds, collisions from .col files) and returns plenty of data: hit point, element, surface normal, material, lighting, body or vehicle part, and on request the map object model with its position. Each call waits about one game frame; while the world is still loading (loading screen) it returnsfalseat once. On the server it uses a simplified model (element spheres, no terrain or buildings).