2D positioning to 3D positioning

Hello! I am working on a GPS system which has been delayed due to me not knowing the math for it. What I want to make is that whenever, and wherever the player clicks in the minimap, it makes a waypoint at that location in the real world. I’ve got some code:

local GPS_BUTTON = script.Parent;

local player  = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()

local location = script.Parent.Parent:WaitForChild("Location")

local UserInputService = game:GetService("UserInputService")

local char = player.Character or player.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")

local locations = {};

local Camera = game.Workspace.CurrentCamera

local origin = UDim2.fromScale(0.5, 0.5)

humanoid.Touched:Connect(function(hit)
    if hit.Name == "GPS" then
        hit:Destroy()

        for index, location in ipairs(locations) do
            location:Destroy()
        end

        locations = {}
    end
end)

GPS_BUTTON.MouseButton1Click:Connect(function()
    if game.Workspace:FindFirstChild("GPS") then return end

    local relPos = Vector2.new(Mouse.X,Mouse.Y)-GPS_BUTTON.AbsolutePosition -- relative position in pixels
    local scale = relPos/GPS_BUTTON.AbsoluteSize -- relative position in scale
    
    scale = UDim2.new(scale.X, 0, scale.Y, 0)

    local newLo = location:Clone()

    table.insert(locations, newLo)

    newLo.Visible = true

    newLo.Position = scale

    newLo.Parent = location.Parent

    local anotherLo = newLo:Clone()

    anotherLo.Visible = true

    anotherLo.Size = UDim2.new(0.116, 0,0.111, 0)

    anotherLo.Position = scale

    anotherLo.Parent = GPS_BUTTON.Parent.Parent.Frame.Map

    table.insert(locations, anotherLo)
    
	local PART = Instance.new("Part")
	
	local desiredWorldPosition = Vector3.new()

	local relX = (newLo.AbsolutePosition.X - origin.X.Scale)
	local absX = (game.Workspace.Terrain.Size.X * 0.5)
	
	local relZ = (newLo.AbsolutePosition.Y - origin.Y.Scale)
	local absZ = (game.Workspace.Terrain.Size.Z * 0.5)
	
	desiredWorldPosition = Vector3.new(relX/absX, 5, relZ/absZ)
	
    PART.Size = PART.Size + Vector3.new(0, 20, 0)

    PART.Position = desiredWorldPosition -- Dunno 

    PART.Anchored = true

    PART.Parent = game.Workspace

    PART.CanCollide = false

    PART.Transparency = 0.5

    PART.Name = "GPS";
end)

But it always positions the part at 1 position no matter where I click in the minimap.

Stuck at this for a while now.

Any help that solves this will make my day. Thank you.

I have a representation of the position in a 2d identity matrix then have that being updated based on the bounds of the map divided by the players position

What do you mean? Mind explaining a bit more?

Do you get what I mean now? The more components in the matrix → the resolution/accuracy of the 2d positioning to 3d positioning. Technically this should be an infinitly wide matrix but idk much about graphing so we are using set bounds

If I’m not wrong, then, is the “xLength” also a “xFactor”? Because I use them when I position the player position in the map.

xLength → the length of the bounds of our map on the x

Oh. Thank you! Also, how would I use to convert a certain position on my map to 3D?
Sorry if this annoying…

Well we dont really know the y factor. What we can do I guess is have a ray cast down when they call it at that position (by just using the inverse operation of our formula) and see where it hits, then apply like idk a 5 stud offset on the y to that

Don’t really care about the Y one. All I want is the X and Z.

Ok so imagine this is my 2D position:

local TwoD = UDim2.fromScale(0.5, 0.5)
local BoundsX, BoundsY = 2, 5

local playerPos = someRandomUDim

local ThreeDX, ThreeDZ = ((TwoD.X.Scale/BoundsX)/playerPos.X), ((TwoD.Y.Scale/BoundsY) / playerPos.Z)

local vec = Vector3.new(ThreeDX, 10, ThreeDZ)

Is the “vec” the correct position?

you cant rely on the actual gui position, instead use the matrix as the reference. The gui is just the interpretation of our matrix visually

1 Like

How would I get the matrix? Thanks for your help so far!

A matrix is just a table within a table in a sense. I suggest you watch my video on them

Thank you so much, I have another question. Do I get the matrix of the playerPosition on the GUI or the one in world space?

The gui isnt manipulating the matrix nor is the worldspace. The matrix is there as a way to interpret the data. The gui and worldspace are also ways but you can think of the matrix as like the base interpreter

Oh, I get it now. If I need any help, will you be active?

Class man :roll_eyes: I might be able to get on between classes but I’ll be out in like 5 hours

Ok, thank you. Mind adding me on discord?