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.