So im scripting security camera’s that follow the player if there in view, so i use raycasting and WorldToScreenPoint but if the player is on the side of the camera, the camera isnt able to detect the player.
local GetThingsInView = function(Delta)
if Character:FindFirstChild("Camera") then
for _, v in pairs(workspace:GetDescendants()) do
if v:IsA("Model") then
if v:FindFirstChild("Humanoid") then
local _, visible = workspace.CurrentCamera:WorldToScreenPoint(v.PrimaryPart.Position)
local Distance = (Camera.CFrame.Position - v.PrimaryPart.Position).Magnitude
local Parameter = RaycastParams.new()
Parameter.FilterType = Enum.RaycastFilterType.Whitelist
Parameter.FilterDescendantsInstances = {v}
local CastRay = workspace:Raycast(Camera.CFrame.Position, Camera.CFrame.LookVector * 150, Parameter)
local Camera_Tables = Get_Camera()
if visible and Distance <= 50 and CastRay then
Framework_Gui.Full_Frame.CamFrame.Tracker.Text = "CURRENTLY TRACKING : ".."<font color=\"#affed0\">"..string.upper(v.Name).."</font>"
Framework_Gui.Full_Frame.CamFrame.Distance.Text = "DISTANCE : ".."<font color=\"#affed0\">"..Distance.."</font>"
Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, v.PrimaryPart.Position)
else
if Camera_Tables then
Camera.CFrame = Camera_Tables.Position
Framework_Gui.Full_Frame.CamFrame.Tracker.Text = "CURRENTLY TRACKING : ".."<font color=\"#fe4141\">".."NO ONE".."</font>"
Framework_Gui.Full_Frame.CamFrame.Distance.Text = "DISTANCE : ".."<font color=\"#fe4141\">".."NIL".."</font>"
end
end
end
end
end
end
end