Help with Viewport Map Icons

Hey, and thanks for reading in advance.

I’m creating a map using a ViewportFrame that’s updated in real-time, showing the positions of every player and other specific game element states.

Problem being - currently, the X coordinate of my icon is inaccurate, and it outpaces my movement when I walk in either direction.

The X coordinate is only correct when I approach the center of the map, and the Y coordinate appears to be 100% accurate to my location regardless of where I am.

Here’s the snippet that updates the map on a RenderStep bind:

function updateMap()
	if mapModels ~= {} then
		local IconFolder = UI.MapView.Viewport:FindFirstChild("IconFolder")
		
		if not IconFolder then
			IconFolder = Instance.new("Folder")
			IconFolder.Name = "IconFolder"
			IconFolder.Parent = UI.MapView.Viewport
		end
		
		for _,Member in pairs(game.Players:GetPlayers()) do
			if Member.Character and Core:GetStat(Member.Character, "Health", 0) > 0
				and Member.Character:FindFirstChild("HumanoidRootPart")
			then
				local Icon = IconFolder:FindFirstChild(Member.Name)
				local M_Root = Member.Character.HumanoidRootPart
				local Vector, InView = miniCam:WorldToViewportPoint(M_Root.Position)
				
				if not Icon then
					Icon = Instance.new("ImageLabel")
					Icon.Image = "rbxassetid://"..10581359974
					Icon.ImageColor3 = Member.TeamColor.Color
					Icon.BackgroundTransparency = 1
					Icon.ZIndex = 5
					
					Icon.Size = UDim2.new(.1, 0, .1, 0)
					Icon.Position = UDim2.new(Vector.X, 0, Vector.Y, 0)
					Icon.SizeConstraint = Enum.SizeConstraint.RelativeYY
					
					Icon.Name = Member.Name; Icon.Parent = IconFolder
				else
					Icon.Position = UDim2.new(Vector.X, 0, Vector.Y, 0)
				end
				
			elseif IconFolder:FindFirstChild(Member.Name) then
				IconFolder[Member.Name]:Destroy()
			end
		end
	end
end

If anyone knows what’s causing this behavior, I’d be thankful. I have a suspicion the camera is involved, as my icon’s position changes when I jump, despite that not being a change in my planar coordinates.

You need to convert your scale positions i believe, like this:

Your math suggests that the minimap model of the map is the same scale as the real map, is that the case?

Correct. Same scale, same position.

Is it possible the position M_Root.Position is closer to the camera than it should be? That would make it appear to be scaled wrong, consistent with what you see.

Looks like I found the solution I was looking for here.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.