Top Down Field of View Effect

Hello,

I want to create a field-of-view effect for a top-down shooter game I’m working on. The following video has exactly what I want: Field of View Effect in Unity (Line of Sight, View Cone) - YouTube

A couple of questions;
Is it possible to make meshes like the one in the tutorial, in a cone shape, to block vision?
How would you achieve this with the most performance? How would you cover up the view, GUIs? Parts?

Here is a quick snippet of what I’ve made to detect if a part could be in render; it seems to work well.

local maxDist = 1100
local range = 71

function isPartInView(head,part)
	local relative = (part.Position-head.Position)
	local forward = head.CFrame.LookVector
	local side = relative.Unit
	local theta = math.deg(math.acos(forward:Dot(side)))
	if (relative.Magnitude < maxDist and theta <= range) then
		local rayParams = RaycastParams.new()
		rayParams.FilterType = Enum.RaycastFilterType.Whitelist
		rayParams.FilterDescendantsInstances = {game.Workspace.Maps:FindFirstChild(game.Workspace.CurrentMap.Value)}
		local rayResult = game.Workspace:Raycast(head.Position,(part.Position-head.Position),rayParams)
		if rayResult then
			return false
		else
			return true
		end
	else
		return false
	end
end

As for some of the other math, and how to actually cover the player’s view, I’m at a loss and I haven’t found anything related on the dev forum.

Is this something you’re looking for? If it is, it has a neat explanation of almost every line.

I have the topdown camera made, I just need to create realistic field of views.


Here is a screenshot of what I’ve got so far, as you can see, you can see right into other rooms. I would like to hide the contents of those rooms if you wouldn’t be able to see it like you can with light rays.

Here is a video recording of the topdown-system.