How can I check if a part is fully englufing the screen?

Hi!

I am currently trying to create a transition effect, where you look at a part that engulfs your whole screen, and then teleports you in a way that you can look behind and be in a different room. For example, something like this
image
but where this would not trigger anything since you can see the surrounding environment thus making it not seamless


I know theres WorldToViewportPoint, but that’s only for a specific point, and I’m not sure how to check if it’s fully engulfed.

Not sure if this is the most practical answer, but you could use Camera:ScreenPointToRay on each corner of the screen. If all 4 rays hit the same part, then it is engulfing the screen. You could also check the distance and normals so that it is aligned correctly.

2 Likes

I’ll experiment, seems like a decent idea. What exactly does the depth mean in this instance?

I’m testing it with the top left, seems to be doing nothing intentional. I can’t even tell what it’s doing wrong, all I know is that my origin is correct

--!strict

local camera = workspace.Camera
local cameraSize = camera.ViewportSize

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace:WaitForChild("Joshument")}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

while true do
	task.wait(0.1)
	local topLeftRay = camera:ScreenPointToRay(0, 0, 1)
	
	--[[
	local part = Instance.new("Part")
	part.Anchored = true
	part.Size = Vector3.one
	part.Position = topLeftRay.Origin
	part.CanCollide = false
	part.Transparency = 0.5
	part.Parent = workspace
	]]
	
	local topLeftRaycast = workspace:Raycast(topLeftRay.Origin, topLeftRay.Direction)
	if topLeftRaycast then
		print(topLeftRaycast.Instance.Name)
	end
end

Looks like I got it to work, I’m just assuming the Ray that’s returned is a Unit vector and I needed to increase how far the vector traveled

--!strict

local camera = workspace.Camera
local cameraSize = camera.ViewportSize

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.TestFolder, workspace.TestFolder.TestPart}
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist

while true do
	task.wait(0.1)
	local topLeftRay = camera:ScreenPointToRay(0, 0, 0)
	
	local topLeftRaycast = workspace:Raycast(topLeftRay.Origin, topLeftRay.Direction * 100, raycastParams)
	if topLeftRaycast then
		print(topLeftRaycast.Instance.Name)
	end
end

Yes you’re correct, it does return a unit vector. Sorry I couldn’t answer, I had to sleep.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.