Hello,
Recently, I encountered a problem with converting the world gameobject’s position to a 2D UI Image.
I want to show player’s realtime position on 2d image, no matter what resolution/size the image is because I already designed the map in photoshop with all the structures/locations.
I tried to do so, but I can’t match the coordinates and the distances arent right.
I have no idea, how can I do that
Normally it’s just a straight up scale problem. Divide the characters position by the size of the world in world units, then multiply it by the size of the map in the appropriate units (screen space or pixels) then you are done.
Any way you like. If you’re using a terrain system, you can use the size and scale of the terrain to give you your dimensions, or you can just use a big box object that you keep invisible except when you want to see your world’s boundaries, or you can set an empty GameObject in the middle of your playable area and just calculate everything relative to that point, etc…
One cute way is to use a “plane” object and actually give it a texture/material for your drawn map, then scale it so that looking at it from above with an orthographic camera matches the actual dimensions of the area perfectly- I’m a big fan of this.