M MY Multiplayer: Wiki
Side
Kind

getScreenFromWorldPosition

Client

Projects a world point onto the screen, with the current frame's camera.

float, float, float|false getScreenFromWorldPosition(float x, y, z [, float edgeTolerance = 0, bool relative = true])

Parameters

NameTypeDescription
x, y, zfloatThe point in the world. A vec3 also works.
edgeTolerancefloatHow far off screen the point may be and still be returned.default 0
relativeboolIf true, the tolerance is a fraction of the screen's width and height; if false, it is in pixels.default true

Returns

The x, y coordinates in pixels and the point's distance from the camera along its view direction. false if the point is behind the camera or off screen past the tolerance.

Example

addEventHandler("onClientRender", root, function()
    local pos = getElementPosition(localPlayer)
    local sx, sy = getScreenFromWorldPosition(pos.x, pos.y, pos.z + 1.2)
    if sx then
        dxDrawText("Me", sx, sy)
    end
end)

See also