Is there any possible way to know whether a part is within your field of view? I have looked around in the Wiki, and I haven't found anything of the sort... So if there is any way to create a method that can detect objects within your field of view, that'd be nice to know! Thanks in advance!
EDIT: Perhaps the term "Line of sight" would be better instead of FOV? I want to detect if the player can see a part, that's all.
Do this:
First make a localscript and put it in StarterGui
then put this code in the localscript
Code:
local Camera = game.Workspace.CurrentCamera local FOV = Camera.FieldOfView -- Field Of View :: INFO - Field Of View goes by radius local Player = game.Players.LocalPlayer local Parts = {} function Scan(Parent) for i, v in pairs(Parent:GetChildren()) do table.insert(v) if #v:GetChildren() > 0 then Scan(v) end end end Scan(Workspace) function GetPart(Player) for i=1, #Parts do if (Player.Character.Torso.Position - Parts[i].Position).magnitude < FOV then return Parts[i] end end end game:GetService("RunService").RenderStepped:connect(function() local Part = GetPart(Player) print(Part.Name) end)
want to know more about magnitude
and RunService
click the links below:
Hmm....I've never heard of this, and my scripting isn't that advanced. But, I do have an idea. Try making a script that creates a part on the front part of your character that is attached to where your head is. And then make a script on what it needs to do, and then put that script into the part that is created via script.