- Home /
Problems with Rect
Hello,
I am making currently a radar/minimap and I ran into one issue. I am checking if the blip is within the minimap's rect by using Rect.Contains method and for the rectangular minimap this works just fine, but for the circle shaped minimap this doesn't apply anymore.
Is there a way to check this for the circle shaped minimap? Thank you.
Answer by swoop7 · Oct 18, 2018 at 03:08 AM
Funnily enough I have been playing around with a Circle based radar. I'm guessing your issue is that the Blip shows up past the circle in the top left, right and bottom left right?
I'm also assuming you are doing a math based radar? Not a camera being drawn onto a Rect with RenderTexture?
Just check if the position of the Blip is within a radius from the center of the radar;
// Pseudocode:
// Ratio of how big the radar is on the screen
float radarScale = 0.2f;
// Get width of radar based on screen
float _radarWidth = (Screen.width * radarScale)
// distance between what is the center of your radar (could be player transform)
// and the transform of the Blip (e.g. enemy)
float dist = Vector3.Distance(centerPos, enemyPos);
// if distance less than 90% the radarWidth divided by half (to give radius)
if (dist <= (_radarWidth * 0.9f) * 0.5f)
{
// Your draw logic here
}
I do 90% of the width because then it doesn't draw it on the actual edge of the circle, meaning it stops drawing the blip just before it hits the circle edge
Your answer
![](https://koobas.hobune.stream/wayback/20220612180508im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
circle image on a cylinder? 1 Answer
Why can't GUI.Box have a width of 5 or less? 1 Answer
Touch screen coordinates is not same Rect class coordinates? 1 Answer
Bounds vs. Rectangle 1 Answer
Drawing a Circle instead of Rect 1 Answer