I am brand new to viewports, never used them before. So if you want to suggest me to do some calculation to fix the code you have to provide it or i will not understand how to do it at all.
I have the following script:
local Minimap = script.Parent:WaitForChild("Minimap")
local Arrow = Minimap:WaitForChild("Arrow")
local IconsFolder = game.Workspace:WaitForChild("Icons")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Camera = Instance.new("Camera")
Camera.FieldOfView = 1
Camera.CameraType = Enum.CameraType.Scriptable
Camera.Parent = game.Workspace
Minimap.CurrentCamera = Camera
task.wait(2)
for i, child in pairs(game.Workspace.Icons:GetChildren()) do
local W2VP = Camera:WorldToViewportPoint(child.Position)
local X = W2VP.X
local Y = W2VP.Y
local TextClone = script.Parent.Parent.TextLabel:Clone()
TextClone.Parent = Minimap
TextClone.Text = child.Name
TextClone.Position = UDim2.new(0, X, 0, Y)
end
local function isPartFromCharacter(part)
return part:IsDescendantOf(Character)
end
for i, Object in pairs(game.Workspace:GetDescendants()) do
if isPartFromCharacter(Object) then
continue
end
if Object:IsA("Terrain") or not Object:IsA("BasePart") then
continue
end
Object:Clone().Parent = Minimap
end
game:GetService("RunService").RenderStepped:Connect(function()
local camCFrame = CFrame.new(HumanoidRootPart.Position + Vector3.new(0, 5000, 0), HumanoidRootPart.Position)
Camera.CFrame = camCFrame
Arrow.Rotation = - HumanoidRootPart.Orientation.Y - 90
end)
i want text labels to be placed in the map relative to where their corresponding part is in the IconsFolder problem is that i dont have the slightest clue how to do that and no tutorials or devofrum posts helped me at all
now if you go into the viewport, you’ll see a nifty thing called the “CurrentCamera”, This is the veiwpoint of the viewport, now you can do 2 things with this
Create a camera at 0,0
Use the “thumbnail camera” that is used when flying around in studio (This is what I will be using)
Now we have set our camera, lets put stuff in the viewport.
without moving the camera place a part infront of yourself (or infront of 0,0) and parent it into the workspace
I copyed and parented the part (now with a frog) without having moved the camera into the viewport, and now we can see it in both the workspace and the veiwport
The solution I currently have right now is to make some logos in MSpaint, and have them be on parts high up in the sky that make it seem like they’re images.
There’s may be a solution you can do involving map size and a lot of math, but I personally don’t know how to do that. and for a map based on veiwports, probably not the best idea either.
local Minimap = script.Parent:WaitForChild("Minimap")
local Arrow = Minimap:WaitForChild("Arrow")
local IconsFolder = game.Workspace:WaitForChild("Icons")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Camera = Instance.new("Camera")
Camera.FieldOfView = 1
Camera.CameraType = Enum.CameraType.Scriptable
Camera.Parent = game.Workspace
Minimap.CurrentCamera = Camera
task.wait(2)
local function isPartFromCharacter(part)
return part:IsDescendantOf(Character)
end
for i, Object in pairs(game.Workspace:GetDescendants()) do
if isPartFromCharacter(Object) then
continue
end
if Object:IsA("Terrain") or not Object:IsA("BasePart") then
continue
end
Object:Clone().Parent = Minimap
end
for i, child in pairs(game.Workspace.Icons:GetChildren()) do
local W2VP = Camera:WorldToViewportPoint(child.Position)
W2VP = Camera:WorldToViewportPoint(child.Position)
local TextClone = script.Parent.Parent.TextLabel:Clone()
TextClone.Text = child.Name
TextClone.Name = child.Name.."GUI"
TextClone.Position = UDim2.new(W2VP.X, 0, W2VP.Y, 0)
TextClone.Parent = game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap
TextClone.BackgroundTransparency = 1
end
function add()
for i, child in pairs(game.Workspace.Icons:GetChildren()) do
local W2VP = Camera:WorldToViewportPoint(child.Position)
game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap:FindFirstChild(child.Name.."GUI").Position = UDim2.new(W2VP.X, 0, W2VP.Y, 0)
end
end
function characterIcon()
local W2VP = Camera:WorldToViewportPoint(Player.Character.HumanoidRootPart.Position)
W2VP = Camera:WorldToViewportPoint(Player.Character.HumanoidRootPart.Position)
game.Players.LocalPlayer.PlayerGui.MinimapGui.Minimap.Arrow.Position = UDim2.new(W2VP.X, 0, W2VP.Y, 0)
end
game:GetService("RunService").RenderStepped:Connect(function()
--local camCFrame = CFrame.new(HumanoidRootPart.Position + Vector3.new(0, 10000, 0), HumanoidRootPart.Position)
local camCFrame = CFrame.new(game.Workspace.Baseplate.Position + Vector3.new(0, 10000, 0), game.Workspace.Baseplate.Position)
Camera.CFrame = camCFrame
Arrow.Rotation = - HumanoidRootPart.Orientation.Y - 90
add()
characterIcon()
end)
I hope this helps someone who is looking for an answer sometime in the future.