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.
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)
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.
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?
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
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.