Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configurable Constants
- local RANGE = 128
- local RADAR_DIM = 20
- -- Services
- local RS = game:GetService("RunService")
- -- Player Objects
- local plr = game.Players.LocalPlayer
- repeat wait() until plr.Character
- local char = plr.Character
- local torso = char:WaitForChild("Torso")
- local hum = char:WaitForChild("Humanoid")
- local cam = workspace.CurrentCamera
- -- UI Objects
- local radarGui = script.Parent
- local radarFrame = radarGui.Radar
- -- Shoots a ray from a position
- local function shootRay(pos)
- local ray = Ray.new(pos, Vector3.new(0, -1024, 0))
- local hit, pos, normal, material = workspace:FindPartOnRay(ray, char)
- return (hit ~= nil) and hit.BrickColor.Color or false
- end
- local steps = 0
- -- Bind to RenderStep
- RS:BindToRenderStep("UpdateRadar", Enum.RenderPriority.Last.Value, function()
- steps = steps + 1
- if steps % 10 ~= 0 then return end
- local radarChildren = radarFrame:GetChildren()
- for i = 1, #radarChildren do
- radarChildren[i]:Destroy()
- end
- if torso.Parent then -- If the torso still exists
- local torsoPos = torso.Position + Vector3.new(0, 64, 0)
- local cam2DLookVector = Vector3.new(
- cam.CoordinateFrame.lookVector.X, 0, cam.CoordinateFrame.lookVector.Z
- ).unit
- local torsoPointCF = CFrame.new(torsoPos, torsoPos + cam2DLookVector)
- local inc = RANGE / RADAR_DIM
- for x = -RANGE/2 + inc/2, RANGE/2 - inc/2, inc do
- for y = -RANGE/2 + inc/2, RANGE/2 - inc/2, inc do
- local pos = (torsoPointCF * CFrame.new(x, 0, y)).p
- local color = shootRay(pos)
- if color then
- local ui_x = (x + RANGE/2 - inc/2) / inc
- local ui_y = (y + RANGE/2 - inc/2) / inc
- local pixel = Instance.new("Frame", radarFrame) do
- pixel.Size = UDim2.new(1/RADAR_DIM, 0, 1/RADAR_DIM, 0)
- pixel.Position = UDim2.new(ui_x/RADAR_DIM, 0, ui_y/RADAR_DIM, 0)
- pixel.BackgroundColor3 = color
- pixel.BorderSizePixel = 0
- end
- end
- end
- end
- end
- end)
- hum.Died:connect(function()
- RS:UnbindFromRenderStep("UpdateRadar")
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement