GetScreenCoords
This function was added in DSL 10
Description
Convert world coordinates to screen coordinates.
This function retrieves the screen coordinates of a point in the game world, given its world coordinates (x, y, z). It is useful for converting 3D positions into 2D screen positions for rendering or UI purposes.
If the position is not on screen, it returns nil
for the screen coordinates.
function GetScreenCoords(x, y, z) --[[ ... ]] end
Parameters
x
:number
- The x-coordinate in the game world.y
:number
- The y-coordinate in the game world.z
:number
- The z-coordinate in the game world.
Return Values
screenX
:number?
- The x-coordinate on the screen, ornil
if the point is not visible. Range 0 to 1.screenY
:number?
- The y-coordinate on the screen, ornil
if the point is not visible. Range 0 to 1.
Example
-- In front of the boys' dorm
local screenX, screenY = GetScreenCoords(270, -113, 7)
if screenX and screenY then
print('Screen coordinates:', screenX, screenY)
else
print('Point is not visible on screen.')
end