Search Unity

Looking for easy way to combine several circles to form one contiguious shape

Discussion in 'General Discussion' started by Texashawk, Jan 17, 2020.

  1. Texashawk

    Texashawk

    Joined:
    Mar 19, 2013
    Posts:
    43
    Basically, like this - the two green hatched circles are joined and become one shape:
    CombiningCircleExample.jpg
    I'm essentially looking for a combine operation with 2 circle sprites. Is there an easy way to do this sort of thing with Unity, or do I have to go with a mesh, or is there another way/plug-in that would do this?

    Thanks!
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,570
    There are multiple ways to go about it, but none of them are "easy".

    Basically you can calculate circle intersection yourself, and create outline using line renderer.
    Or you could implement them as an image effect.
    Or you could try using stencil buffer for masking.
    Or you could try depth masking with invisible sprite. (first you render a transparent mask sprite which is invisible but writes into depth buffer, and is slightly in front of the "green line" sprite, then you render the "green line sprite")

    The screenshot you posted seems to belong to some sort of 4x game, meaning there will be more than just two circles.
     
  3. Lapsapnow

    Lapsapnow

    Joined:
    Jul 4, 2019
    Posts:
    51
    I know this post is old, but I'm sharing this info anyway.

    Simple!
    You can merge the circles, using two objects. "A" circle sprite and "B" sprite mask.
    If you set A's to "Visible Outside Mask" then B will mask all instances of A. Creating nice merging.

    If you want different circle merges for different purposes, the layer setting can be used. Attack range, build range, etc.

    ( Ignore that I duplicated the prefab inside itself, it's just to demonstrate )
     

    Attached Files:

    Last edited: Jul 13, 2022