Hello, I want to make a minimap using ViewFrames but the issue is parts that are in the way, i found out I can use Camera:GetPartsObscuringTarget but im not sure how to.
Here is my code:
local viewPort = script.Parent:WaitForChild("ViewportFrame")
local charPart = viewPort:WaitForChild("Player")
local roads = workspace:WaitForChild("Roads")
local buildings = workspace:WaitForChild("Buildings")
local hotkey = Enum.KeyCode.M
local UIS = game:GetService("UserInputService")
local open = false
local frame = script.Parent.Parent
UIS.InputBegan:Connect(function(key, gp)
if key.KeyCode == hotkey then
if UIS:GetFocusedTextBox() == nil then
if open == false then
open = true
frame.Visible = open
elseif open == true then
open = false
frame.Visible = open
end
end
end
end)
roads:Clone().Parent = viewPort
buildings:Clone().Parent = viewPort
local camera = Instance.new("Camera", workspace)
camera.CameraType = "Scriptable"
local height = 300
local player = game.Players.LocalPlayer
repeat wait() until player.Character
viewPort.CurrentCamera = camera
game:GetService("RunService").RenderStepped:Connect(function ()
local position1 = player.Character.HumanoidRootPart.Position
camera.CFrame = CFrame.new(Vector3.new(position1.X,height,position1.Z), position1)
charPart.CFrame = player.Character.HumanoidRootPart.CFrame
end)
--raycasting
local roads = workspace:WaitForChild("Roads")
local buildings = workspace:WaitForChild("Buildings")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:FindFirstChild("Head")
local ray = Ray.new(head.Position, Vector3.new(0,50,0))
local Camera = game.Workspace.Camera
while wait(1) do
local ray = Ray.new(head.Position, Vector3.new(0,50,0))
local whiteList = {roads, buildings}
local hit, position = game.Workspace:FindPartOnRayWithWhitelist(ray, whiteList)
if hit then
print('ray hit a part!')
else
print('no part found')
end
end
I get a print in the output saying that my ray has hit a part but i want that part to be removed, can someone please help me?