Converting Image Coordinates to World Coordinates

I’m attempting to make a plotting system for my game where a player chooses their base location by dragging a square on an image of the map.

How do I convert the location of the square on the image to world cords?

So far I’ve been extracting my mouse position value when DraggerStopped is true to test. The system to place the plot to a given coordinate is already complete.


I just need to figure out how to translate image cords into world cords. I’ve tried placing the user’s camera above the map, that does not go well on a slow connection or mobile so this seems like the next best thing.

Let me know if you need any more info. Thanks.

Does this suffice?

Usually there’d be some sort of world-screen ratio. For example, the map (in pixels) will be half the size of the actual map (in studs). Then you do a conversion:

local MinimapScale = 0.5
local PositionInWorldSpace = Vector3.new(SelectedX/MinimapScale,0,SelectedY/MinimapScale)

I don’t think it does but that may be useful when detecting UI collisions later on.

It gives a direct ray from that position on the screen to the world as seen by the player though, that should return the world coordinates you are after.

1 Like

I see, you’re talking about ditching the UI, placing the camera over the map, letting the user click where they want their plot on the terrain, and done. Right?

That is not mutually exclusive with the UI though, you can still render that on top of it for the visual appeal.

local function projectScreenPointToWorldGeometry(x, y)
	local ray = workspace.CurrentCamera:ScreenPointToRay(x, y)
	local _, pos = workspace:FindPartOnRay(Ray.new(ray.Origin, ray.Direction*5000))
	return pos
end

I think x and y would be the args of DragStopped.

1 Like

Thanks for the help everyone, I aligned the UI map up with the actual map and used ScreenPointToRay as suggested then sent the cords to the plotting code to do checks and place if it’s a valid plot. The system works well now.