One of the authors of a marketplace minimap asset here. I can share some of my experience developing the minimap. When you want to render part of the minimap’s background texture based on the player’s position, first of all you need to have a background texture made and know what world XY coordinates it maps to. Then you compute the player’s position in the coordinate space of the background texture. Then you convert that to texture sampling (UV) coordinates.
As a simple case, let’s say that you have a 512x512 background texture and it represents a 1024x1024 area in the world centered around the world origin (0, 0, 0). I’ll call the world area that the background texture maps to the “background volume”. Lets say the player’s world position is (100, 100, 0). Ignoring Z coordinate because it is unimportant, the background volume goes from XY = (-512, 512) to (512, 512). The player’s relative position within that volume is computed via ‘inverse lerp’: U = X - MinX / MaxX - MinX, so:
[table=“width: 200”]
U =
100 - (-512)
512 - (-512)
= 0.6
Or the player’s X coordinate is 60% along the background volume’s X range. And we used the same values for Y. In other words, in the background volume’s coordinate space where (0.0, 0.0) corresponds to world (-512,-512) and (1.0, 1.0) corresponds to world (512,512) the player’s position would be (0.6, 0.6).
Now recall that we had a texture that maps exactly to the background volume. Texture sampling (also known as UV) coordinates go from 0.0 to 1.0, so to render the area around the player, we now render around UV coordinate (0.6, 0.6). For example, we could render the minimap with UV coordinates ranging from (0.6 - r, 0.6 - r) to (0.6 + r, 0.6 + r), where r = 0.1 or can be varied to control how far the player can see on the minimap.
Once you understand the simple case, you can try implementing a minimap that rotates or having a background volume that isn’t centered around the world origin and is rotated as well. The most important part is to understand what coordinate spaces you are converting between. I can give an overview:
- World space: Everything’s position relative to the world origin.
- Background space: Everything’s position relative to the background volume’s center (or a corner) and the background volume’s rotation. Distances are the same as in world space.
- Background UV space: Same as background space but all coordinates that are inside the background volume are rescaled to 0.0 - 1.0. These values are usable as texture sampling coordinates.
In the simple case we didn’t have to do anything to obtain background space coordinates from world coordinates, because the background volume has the same origin and rotation.
If you are familiar with the terms view space and projection space, the background space and background UV space are exactly that. There are actually camera calculations in 2D. Hope this helps you out.