Detecting If something is visible

I’m trying to figure out how I can check if a part is visible for a lens flare system, I cant figure out how to check without raycasts and I haven’t tried with them because I’m not super skilled with them.

Pretty much I need help figuring out :
Is the part on screen?
Is the part blocked?

1 Like

Could you not just check if an if statment??

1 Like

What would I check? I don’t think there’s any built in way to do what I want

1 Like

Raycast from the player’s head to the part and check if something is hit – if the hit part is the part you are checking for visibility then the player has Line of Sight of the part.

1 Like

I understand not trying raycasts if you dont know how to use them or aren’t especially good at using them but eventually you’ll absolutely need it for something you want or need to make, and its actually surprisingly simple to use raycasts.

local Part = script.Parent

local raycastparams = RaycastParams.new() --This is the parameters you set for the raycast
raycastparams.FilterDescendantsInstances = {Part}
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.IgnoreWater = true

local castresult = workspace:Raycast(Part.Position,Part.Position+Vector3.new(0,50,0),raycastparams)
--The first argument is the starting position of the raycast (its origin)
--the second argument is the end position (or target) of the raycast
--the third argument (which is optional) is the parameters of the raycast

if castresult then --Checks if the raycast hit anything
	local HitPart = castresult.Instance--This is the part the cast hit
	print("The raycast hit something above the part!")
else
	--The raycast didn't hit anything
	print("There was nothing in the range/direction of the part :(")
end

In this short code I made parameters for the raycast so that it didn’t hit the part it was shooting from, shot it facing 50 studs upwards from the position of the part it starts at, and checked if the raycast hit anything in its direction

This kind of raycast can be shot from the players head or torso to check if something is infront of the player and therefore “blocking” line of sight or movement, but I am not sure about checking if something is onscreen, there is probably something for that in currentcamera though
I found this in one quick search though; Camera | Roblox Creator Documentation

2 Likes