I'm trying to make a billboard GUI that is always-on-top, but I don't like how it shows over every single object. I want to make a script that hides the GUI if there is an object blocking the camera's view of the GUI's Parent brick. No, don't just say to turn off the always-on-top, because it has clipping issues and it ruins the look of it being a light glare. The problem with this, even though I am pretty good at scripting, is that I have no idea on how to do this. I have never used raycasting before so I have no idea how it works. Can someone with more scripting knowledge help me with this? I've searched Google everywhere and on the Roblox website and never found a single thing about this.
This is some code from a script that does something similar, it's a lens flare script made by pulsarnova. I'm having trouble understanding what it does.
wait(2)
local Camera = game.Workspace.CurrentCamera
local Lighting = game.Lighting
local Frame = script.Parent.ShineOverlay
local Visible = true
while wait(1/30) do
local CameraAngle = (Camera.CoordinateFrame.p-Camera.Focus.p).unit
local SunAngle = Lighting:GetSunDirection()
local Trans = 1.5-(SunAngle-CameraAngle).magnitude/3
local LightRay = Ray.new(game.Players.LocalPlayer.Character.Head.Position, SunAngle*999)
local Hit, HitPos = game.Workspace:FindPartOnRay(LightRay, game.Players.LocalPlayer.Character)
if not Hit then
if not Visible then
Visible = true
for n = 1,5 do
wait()
Frame.BackgroundTransparency = 1-(1-Trans)*n/5
end
end
Frame.BackgroundTransparency = Trans
else
Frame.BackgroundTransparency = 1
if Visible then
Visible = false
for n = 1,8 do
wait()
Frame.BackgroundTransparency = Trans+1*n/8
end
end
end
end
