- Home /
How can I draw a circle around an object
Hello,
I've got a problem, I need to show a range of visibility by drawing a circle around an object, however, if an other object is in the range, behind this object shouldn't be visible, how can I process to "cut" the circle ?
For now, I don't have any code, I'm gathering the working process.
edit : because the inner circle is filled, I think that should be a bit harder to do that
Thanks for you ideas
Hello, I have more informations for you, I intend to load a texture of a round created by myself, now I need to know how I can create the "shadow" on this texture of the object that is hiding the vision, I think I can do it with Physics.Raycast, but in this way I will need to change every pixels, and that will be a gigantic loop (even double loop).
So maybe there's a better way.
Thanks.
Answer by whydoidoit · Feb 27, 2014 at 01:20 PM
Well I'd not make it a true circle - I'd cast outwards from the central point a number of rays of the maximum length of the radius of the circle. I would then use the length before the ray hit something to create a polygon between the edge points and the centre. If you used 32 rays it would probably look circular enough.
Cast 32 rays from the centre of the visibility circle with a maximum range of the visibility length
If the ray doesn't hit anything record the positing at the extent of the ray
If the ray intersects something then record the point of intersection
Create a new mesh (or update a mesh) setting the vertices of each triangle to be the centre of the area and each two adjacent points from the array of collisions.
Optionally have the mesh drawn with a renderer that uses depth so that the objects that where hit by the ray correctly appear in front of the parts of the circle which (due to inaccuracies in only casting 32 rays) overlap.
Thanks you, I have now a better idea of how I'm going to do this :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613134806im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using 2d image for dragging? 0 Answers
How to know if gameobject is in a circle in my canvas? 1 Answer
Drawing a Range Icon in 3D Space 0 Answers
How to limit Cannon shooting for certain range in unity 2d ? 0 Answers
Best practice for tiled 3D terrain 0 Answers