If you look at a SurfaceGui from an angle, you can view it at much higher distances than looking straight at it. I am wondering how I would detect if a SurfaceGui is visible, my current code just gets the distance from the center of the face to the camera.
Surface:
-- Gets face
local Face = SurfaceGui.Face
if not Face then return 0 end
-- Gets center of face
local FaceCFrame = Adornee.CFrame * CFrame.new((Adornee.Size/2)*KiwiUtility.FaceList[Face.Name])
-- Gets distance to camera
return (Camera.CFrame.Position - FaceCFrame.Position).Magnitude
Billboard:
-- Distance checks
local Distance = (Camera.CFrame.Position - WorldPosition).Magnitude
if IgnoreCovering == nil and BillboardGui.MaxDistance > 0 then
if Distance > BillboardGui.MaxDistance then return false, Vector2.new(), Distance end
end
This same issue also happens with billboards, I can’t make bug reports so I am just asking for a workaround.
SurfaceGui (this just returns the distance from the closest point on the respective surfaceGui.Face), compare this directly with surfaceGui.MaxDistance to return whether or not it’s currently visible, point would be Camera.CFrame.Position:
local function calculateDistanceFromClosestPointOnFace(point, part)
local surfaceGUi = part:WaitForChild('SurfaceGui')
local face = surfaceGui.Face
local faceVec = Vector3.fromNormalId(face)
local pointOnFace = faceVec * 0.5 * part.Size
local pointOnPart = part.CFrame * CFrame.new(pointOnFace)
local cameraLocal = pointOnPart:PointToObjectSpace(camera.CFrame.Position)
local clampedToFace = cameraLocal:Max(-0.5 * part.Size):Min(0.5 * part.Size) * (Vector3.one - faceVec:Abs()) + pointOnFace
return (point - pointOnPart:PointToWorldSpace(clampedToFace)).Magnitude
end
As for Billboard, are you using any of the offsets? That will complicate things a bit, let me know.