Problem with Minimap.

I’ve made a HUD for my game, which has a space for the minimap, which is just a camera pointing down to the player.

I’m trying to make it so that the minimap is always within that space and the same size, regardless of resolution. Right now, whenever I play it maximised, the Minimap gets too big, and is outside of the HUD.

How do I fix this?

EDIT: Here’s my code:

	public float desiredWidth;
	public float desiredHeight;
    public float desiredX;
	public float desiredY;
	
	void Awake()
	{
		float nWidth = desiredWidth / Screen.width;
		float nHeight = desiredHeight / Screen.height;
		float nX = desiredX;
		float nY = desiredY;
		gameObject.camera.rect = new Rect(nX, nY, nWidth, nHeight);
	}

Adjusting (by script) the width and height of your minimap camera by dividing the screen width and height to your needs. That way the minimap will always be proportional to the screen.

By default, the values you set in the inspector are Normalized position in screen space [0-1] This means that what you see will be different on each resolution because the screen size is different.

So what you need to do if you want a fixed size, if write a script that has a calculation in the awake or start method that calculates the normalized values for the size and position based on the screen size. These calculations for the new normalized size should do the trick.

float nWidth = desiredWidth / Screen.width;
float nHeight = desiredHeight / Screen.height;

working out the position will depend on how you want it positioned, aligned to the side, distance from center, etc. So i’ll leave you to work out the calculations for that one.

Hi Cobra!

We have created the KGFMapSystem (unity3d minimap) and after very long discussions we also decided to control the size of our minimap in normalized coordinates (0-1 relative to the screen widht) instead of making it pixelperfect.

The reason for this is that we think that creating pixelperfect huds is not a good idea anymore since apple invented the retina display where your 64x64 pixel icon will simply shrink into a point.

So i know that this is not the answer to your question, but a possible solution would be to make sure that your hud will also resize relative to the screensize so the hud will always look the same, on all resolutions (even on a retina display) and keep the minimap sizing as it is?

Michal