Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Help with Raycasting Billboard Gui's?

Asked by 8 years ago

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

1 answer

Log in to vote
0
Answered by 8 years ago
local LightRay = Ray.new(game.Players.LocalPlayer.Character.Head, script.Parent.Adornee)
local Hit, HitPos = game.Workspace:FindPartOnRay(LightRay,  game.Players.LocalPlayer.Character)
if not Hit then
    if not script.Parent[""].Visible.Value then
    script.Parent[""].Visible.Value = true
    end
else
    if script.Parent[""].Visible.Value then
    script.Parent[""].Visible.Value = false
    end

That's how you would do it. Edit to your needs. For more info on Rays go to:http://wiki.roblox.com/index.php?title=Ray.new

Ad

Answer this question