Block-based FOV system

Hello there, I have designed an FOV system for the upcoming game that I’m working on called “Hallway of Time”; An RGD fan-game designed to be harder than the original.

Overview

FOVLength = 20 -- Doesn't exactly mean the amount of studs in length
FOV_X = 7.5 -- FOV's X scale
FOV_Y = 2.5 -- FOV's Y scale

local Blocks = {}

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")

local TemporaryInstances = Instance.new("Folder", ReplicatedFirst) -- Just in case
TemporaryInstances.Name = "TemporaryInstances"

local Head = script.Parent.Head

-- Main Component --
local function CreateBlocks(X, Y, FOVLength)
	local NPCFOVFolder = Instance.new("Folder", TemporaryInstances)
	NPCFOVFolder.Name = Head.Parent.Name

	for Distance = 0, FOVLength, 1 do
		local Field = Distance / FOVLength

		local Block = Instance.new("Part", NPCFOVFolder)

		Block.Anchored = true
		Block.CanCollide = false

		Block.Size = Vector3.new(1 + (FOV_X * Field), 1 + (FOV_Y * Field), 1 + Field)

		task.spawn(function()
			while true do
				task.wait(0.25)
				Block.CFrame = Head.CFrame * CFrame.new(0,0,-(Field * FOVLength)-Field)
			end
		end)

		table.insert(Blocks, Block)
	end
end

CreateBlocks(FOV_X * (FOVLength / 2), FOV_Y * (FOVLength / 2), FOVLength)

What bothers me is how slow it’s moving, then again it’s being delayed to make sure there are no memory leaks or at least lags.

Functionality

First, create a folder named “TemporaryInstances” inside ReplicatedFirst.
Then, create a folder inside TemporaryInstances named after the humanoid stored inside.
Now, create several blocks, layer them in a way that looks like a camera FOV and then store them both inside Blocks and inside the folder named after the humanoid.

Yes, I’m tired so this may not be the best explanation I’ve ever given.

1 Like