WorldToScreen

From Onset Developer Wiki
WorldToScreen

Type: Function
Context: Client
Introduced: v1.0

Description

Projects a 3d world location into 2d screen space location. Also returns a bool indicating whether the 3d location is actually on the screen.

Syntax

WorldToScreen(x, y, z)

Parameters

  • x
    Coordinate X in world space.
  • y
    Coordinate Y in world space.
  • z
    Coordinate Z in world space.

Return Values

  • bResult: True on success or False if the world location is not on screen.
  • ScreenX: Converted screen X coordinate.
  • ScreenY: Converted screen Y coordinate.

Example

Example taken from https://github.com/BlueMountainsIO/OnsetLuaScripts/blob/6ef0c5406e84a434ca2d497c470404802f05e0d6/horizon/client/esp.lua

function OnRenderHUD()
	if EnableESP ~= 1 then
		return
	end

	--local lX, lY, lZ = GetCameraLocation()
	local x, y, z
	local ScreenX, ScreenY = GetScreenSize()
	local t = { 1 }
	--local bones = GetPlayerBoneNames()
	for k, v in pairs(GetStreamedPlayers()) do
		local x, y, z = GetPlayerLocation(v)
		local sX, sY, sZ = WorldToScreen(x, y, z)
		if sZ ~= 0.0 then
			--local length = GetDistance3D(x, y, z, lX, lY, lZ)
			
			--DrawPoint3D(x, y, z)
			--DrawRect(sX, sY, 10.0, 40.0)
			DrawLine(ScreenX / 2, ScreenY, sX, sY)
			DrawBox(sX - 50, sY - 100, 100, 200)
			
			--[[for k2, v2 in pairs(bones) do
				local bX, bY, bZ = GetPlayerBoneLocation(v, v2)
				DrawPoint3D(bX, bY, bZ, 3.0)
			end]]--
		end
	end
end
AddEvent("OnRenderHUD", OnRenderHUD)

See also