Minimap Help - quick maf

So I’m trying to make a minimap. Here is how the code below works:

  1. Finds the local player’s position
  2. Finds the rotation of the camera, and sets the man part to have 360 - Camera.Rotation
  3. Finds the vector from the local player to the part
  4. Places the minimap indicator

However, if the part is behind me, the minimap will show it infront of me. If I try and fix this by doing Y = -Y, it does something totally different. Any help would be great please!


function Vec3ToVec2(Vec3)
	return Vector2.new(Vec3.X, Vec3.Z - (2 * Vec3.Z))
end

local Location = workspace.Test

function Minimap(MainUI, Status, UIE)
	local MiniMap 	= MainUI:WaitForChild("MiniMap")
	local You 		= MiniMap:WaitForChild("You")
	
	local Squares = {}
	
	local MaxDistance = math.abs(MiniMap.AbsoluteSize.X / 2)
	local Scale = 1 -- 1 stud = 1 px
	
	RunService.RenderStepped:Connect(function()
		for i,v in pairs(Squares)do
			v:Destroy()
		end

		if not(LocalPlayer.Character and LocalPlayer.Character:FindFirstChildOfClass("Humanoid") and LocalPlayer.Character:FindFirstChild("HumanoidRootPart")) then return end
		local YourPosition = Vec3ToVec2(LocalPlayer.Character.HumanoidRootPart.Position)
		
		You.Rotation = 360 - math.deg(math.atan2(Camera.CFrame.lookVector.x, Camera.CFrame.lookVector.z))
		
		for i,v in pairs(Location:GetChildren())do
		--	if v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health > 0 then
				local TheirPosition = v				
				if TheirPosition then 
					TheirPosition = Vec3ToVec2(TheirPosition.Position)
								
					local NewVector = YourPosition - TheirPosition
					if NewVector.Magnitude <= MaxDistance * Scale then
						local Them = Instance.new("ImageLabel")
						Them.Parent = You

						Them.Position = UDim2.new(0, NewVector.X * Scale, 0, NewVector.Y * Scale)
						Them.Size = UDim2.new(0, 10, 0, 10)
						Them.Rotation = -You.Rotation
						Them.BackgroundColor3 = Color3.new(1, 0, 0)
						
						table.insert(Squares, Them)
					end
				end
		--	end
		end
	end)
end
1 Like

I can’t find the direct issue with your code; however I have a few questions and tips that could lead to it:

  • When checking the magnitude, if you multiply one side by Scale, you should also multiply the other side. Or just leave the multiplication out entirely.
    MaxDistance is in studs (because you’re multiplying it by scale, which is the basis of my assumption), and NewVector is in studs too, since YourPosition and TheirPosition are directly pulled from the Vector3s.

  • You could just multiply NewVector by Scale instead of doing it on each of its components.

  • Set the AnchorPoint for Them to 0.5, 0.5 so it is consistent with the anchor point of the object in workspace you are getting its data from.

  • How is your minimap setup? For negative values to work properly, the origin point for the frame’s children would need to be in the center of the minimap, meaning their parent frame would need to be positioned to {0.5, 0}, {0.5, 0} inside the actual minimap holder.

The reason I’ve done that is MaxDistance isn’t the actual max distance. The actual max distance is how big half the minimap is in px * scale.

That is how it is set up, ya. Thanks for the help though!

1 Like

This is why you are experiencing that issue. Why are you doing this? You’re inverting that axes.That is equivalent of performing just “-Vec3.Z”

return Vector2.new(Vec3.X, Vec3.Z)

Will solve your issue with the part going behind you when it’s not.

However, you’ll now notice your parts are on the wrong side when you rotate the camera. Your camera is moving inverted as well.

Do not have the

360 -

There. Remove that. These two changes will have your minimap working like you’d expect it to.

2 Likes

I did that, got some more wrong behaviour :confused:

Here the red is on the wrong side of the blue. The behaviour also can’t be described as just being flipped on the X axis, it does quite a lot of weird things.

Yes, I understand it can’t be described as “just that” but I have a testing place which works just fine with my adjustments. If necessary, I can provide you with the file.

1 Like

Yes please, that’d be fantastic!

Sorry about the length of time, work was calling.

I’ve attached an example place that shows the minimap functioning correctly. Notice I’ve also commented out where you are rotating “Them” because this will cause the positioning to be improperly applied.

MiniMap Example.rbxl (17.1 KB)

2 Likes