1개월 전 · Jul 6, 2026 6:20 PM
Calculating screen coordinates without relying on Camera:WorldToViewportPoint:
LUA
local function WorldToScreen(worldPos, camera)
local cframe = camera.CFrame
local rel = cframe:PointToObjectSpace(worldPos)
if rel.Z >= 0 then return nil end -- Behind camera
local fov = math.rad(camera.FieldOfView)
local h = math.tan(fov / 2)
local aspect = camera.ViewportSize.X / camera.ViewportSize.Y
local w = h * aspect
local screenX = ((-rel.X / rel.Z) / w + 1) * 0.5 * camera.ViewportSize.X
local screenY = ((rel.Y / rel.Z) / h + 1) * 0.5 * camera.ViewportSize.Y
return Vector2.new(screenX, screenY)
end