- Documentation
- Client functions
- getScreenFromWorldPosition
Function
getScreenFromWorldPosition
Turns a world point into a screen point (pixels). Returns false when the point is behind the camera or off screen. The third result is the distance from the camera. Useful for text above heads.
Syntax
float, float, float getScreenFromWorldPosition(float x, y, z [, float edgeTolerance = 0, bool relative = true])Arguments
x, y, zfloat- The world point.
edgeTolerancefloat, optional = 0- How far off screen the point may be and still count.
relativebool, optional = truetrue=edgeToleranceas a fraction of the screen width.
Returns
x, y in pixels and the distance, or false.
Example
addEventHandler("onClientRender", root, function()
for _, p in ipairs(getElementsByType("player", root, true)) do
if p ~= localPlayer then
local x, y, z = getElementPosition(p)
local sx, sy = getScreenFromWorldPosition(x, y, z + 1.1)
if sx then dxDrawText(getPlayerName(p), sx, sy, sx, sy, tocolor(255, 255, 255), 1, "default-bold", "center") end
end
end
end)