D3d.World2Screen

From Nomad DB

Translates 3d-world coordinates to 2d-coordinates on the screen.

This function can only be called from inside OnRender event!

Syntax

d3d.World2Screen(x, y, z)
  • x, y, z: number (World coordinates)
  • Returns:
    • visible: boolean (is on screen)
    • x, y: number (screen coordinates)

Example

Draws a white square on the local players' position, which originates at their feet.

function script:OnRender()
	local entityId = GetLocalPlayerEntityId()
	local xPos = GetEntityPosition(entityId, 0)
	local yPos = GetEntityPosition(entityId, 1)
	local zPos = GetEntityPosition(entityId, 2)

	local isVisible, screenX, screenY = d3d.World2Screen(xPos, yPos, zPos)
	if isVisible then
		d3d.DrawRect(screenX, screenY, 50, 50)
	end
end

Related Pages