0% found this document useful (0 votes)
45 views

Aaa

This document defines code for drawing a field of view ring and tracking the closest player character within the field of view in Roblox. It creates a circle drawing object for the FOV ring, sets its properties, and positions it in the camera viewport. A getClosest function finds the closest player by raycasting from the camera and checking the distance to other player characters' heads. On each render step, it checks if the right mouse button is held and if a player is within the FOV ring range, smoothly lerps the camera to that player's head position. The user can delete to disconnect and remove the FOV ring.

Uploaded by

Lile Xeon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Aaa

This document defines code for drawing a field of view ring and tracking the closest player character within the field of view in Roblox. It creates a circle drawing object for the FOV ring, sets its properties, and positions it in the camera viewport. A getClosest function finds the closest player by raycasting from the camera and checking the distance to other player characters' heads. On each render step, it checks if the right mouse button is held and if a player is within the FOV ring range, smoothly lerps the camera to that player's head position. The user can delete to disconnect and remove the FOV ring.

Uploaded by

Lile Xeon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

local FOVring = Drawing.

new("Circle")
FOVring.Visible = true
FOVring.Thickness = 1.5
FOVring.Radius = fov
FOVring.Transparency = 1
FOVring.Color = Color3.fromRGB(255, 128, 128)
FOVring.Position = workspace.CurrentCamera.ViewportSize/2

local function getClosest(cframe)


local ray = Ray.new(cframe.Position, cframe.LookVector).Unit

local target = nil


local mag = math.huge

for i,v in pairs(game.Players:GetPlayers()) do


if v.Character and v.Character:FindFirstChild("Head") and
v.Character:FindFirstChild("Humanoid") and
v.Character:FindFirstChild("HumanoidRootPart") and v ~= game.Players.LocalPlayer
and (v.Team ~= game.Players.LocalPlayer.Team or (not teamCheck)) then
local magBuf = (v.Character.Head.Position -
ray:ClosestPoint(v.Character.Head.Position)).Magnitude

if magBuf < mag then


mag = magBuf
target = v
end
end
end

return target
end

loop = RunService.RenderStepped:Connect(function()
local UserInputService = game:GetService("UserInputService")
local pressed = --[[UserInputService:IsKeyDown(Enum.KeyCode.E)]]
UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) --
Enum.UserInputType.MouseButton2
local localPlay = game.Players.localPlayer.Character
local cam = workspace.CurrentCamera
local zz = workspace.CurrentCamera.ViewportSize/2

if pressed then
local Line = Drawing.new("Line")
local curTar = getClosest(cam.CFrame)
local ssHeadPoint = cam:WorldToScreenPoint(curTar.Character.Head.Position)
ssHeadPoint = Vector2.new(ssHeadPoint.X, ssHeadPoint.Y)
if (ssHeadPoint - zz).Magnitude < fov then
workspace.CurrentCamera.CFrame =
workspace.CurrentCamera.CFrame:Lerp(CFrame.new(cam.CFrame.Position,
curTar.Character.Head.Position), smoothing)
end
end

if UserInputService:IsKeyDown(Enum.KeyCode.Delete) then
loop:Disconnect()
FOVring:Remove()
end
end)

You might also like