Skip to content

Instantly share code, notes, and snippets.

@Fraktality
Created September 27, 2018 01:02
Show Gist options
  • Save Fraktality/6584a3cfcaef36e37b812b7aaa2047e9 to your computer and use it in GitHub Desktop.
Save Fraktality/6584a3cfcaef36e37b812b7aaa2047e9 to your computer and use it in GitHub Desktop.
SurfaceGui space -> world space
-- Vector3 guiPointToWorld(SurfaceGui gui, Vector2 point)
-- SurfaceGui space -> world space
local function guiPointToWorld(gui, point)
local adornee = assert(gui.Adornee)
local normalizedPoint = point/gui.AbsoluteSize
local dir = Vector3.FromNormalId(gui.Face)
local projY = math.abs(dir.z + dir.x)
local projZ = dir.x + math.abs(dir.y)
local origin = Vector3.new(
dir.x - dir.y - dir.z,
dir.y + projY,
dir.z + projZ)*0.5
local surfX = Vector3.new(dir.z, 0, -projZ)*normalizedPoint.x
local surfY = Vector3.new(dir.y, -projY, 0)*normalizedPoint.y
local pos = origin + surfX + surfY
return adornee.CFrame*(adornee.Size*pos)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment