Circular mini-map

I plan to create mini-map from player’s current position in a fixed-size minimap.
#edit - The spoiler explains it way clearer than I do.

Some background:

I plan to create a HUD that would indicate health, in a circular form that I would place in bottom right corner, that’s no problem. The “health” indicator would be a thin bar which would be visible, but would leave huge empty space in middle of the quarter-circle.

However I want to fill this space up with minimap. Here’s the trick, I know how to calculate relative position of player to enemies and place colored dots*, but sometimes that coordinates would fall outside of the visible image, I mean, the red dot will appear outside of the healthbar, but still in the area of image.

I have added couple images to maybe help understand of what I’m meaning (look at the end for spoiler)

    • I will take size of map, divide in promiles (1000 pieces), do same to minimap and for every promile passed on map, dot will be moved to the right.

Technically I got this:

I’m trying to create mini-map in that space only:

But “circular filler of space” which is just background, where I will place minimap on has different shape than circular (it only looks circular because of transparency):

So if I program it to fit within the bounds, it will be rectangular only, leaving some space outside of circle still as a minimap:

So how would I get rid of that area that is transparent outside the visible circle:

You could apply an alpha shader using a round texture to hide the unwanted parts of the minimap texture.
And for the “red dots” just calculate the radius from the center and show them or not.

1 Like

And for the “red dots” just calculate the radius from the center and show them or not.
How would I do that? Normally to calculate distance between A and B I would use Vector2.Distance(), how would I take care of that in HUD?

That depends on how you’re calculating the position and how the dots are actually displayed. Could you show you code? Calculating the distance between two points is just Pythagorean theorem. :slight_smile:
But you could also use Vector2.distance by creating two new Vector2 objects from P1 and P2.

float r = Vector2.Distance(new Vector2(P1.x, P1.y), new Vector2(P2.x, P2.y);
1 Like

That depends on how you’re calculating the position and how the dots are actually displayed.
Quoting:
* - I will take size of map, divide in promiles (1000 pieces), do same to minimap and for every promile passed on map, dot will be moved to the right.

Could you show you code?
I don’t have code for this part yet :(, before I will attempt at programming it, I need to be sure it’s within my range of knowledge and if it’s possible without programming it for 3 months.

Calculating the distance between two points is just Pythagorean theorem. :slight_smile:
:eyes:, how does Pythagorean theorem evolve to calculating distance between two points, especially when they’re linear and don’t involve triangle, on top of it, all 2 variables are missing. What?!

But you could also use Vector2.distance by creating two new Vector2 objects from P1 and P2.
Oh, I thought Vector2 calculated from closest border of P1 to P2, not from center of itself. Good to know. Thanks.

Let’s assume P1 is the center of your minimap and P2 is the dots position. Now calculate the x axis difference of P1 and P2 and the y axis difference of P1 and P2 and you got the lenght of two sides of a triangle.
Then use sqrt(a^2 + b^2) to calculate the length of the third side which is equal to the radius.

Yea, but your calculus involves already knowing where the target is at all. From there you refer Distance P1.x - P2.x, I was thinking of circumstance where you don’t know anything about location at all, but no worries, your previous post helped me a lot, and I think I can get going.

#edit - Ah, I get your point, we were talking about different things.