Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to add more vertices onto a Polygon Collider 2D?

Discussion in '2D' started by AngryCSharpNerd, Nov 16, 2013.

  1. AngryCSharpNerd

    AngryCSharpNerd

    Joined:
    Jul 11, 2012
    Posts:
    18
    I tried searching but couldn't find an answer - is there a way to add more vertices to a Polygon Collider 2D?
     
  2. AlanOToole

    AlanOToole

    Joined:
    Sep 7, 2013
    Posts:
    132
    Try holding shift while you are over the edge of the polygon. You should then be able to click, and drag, out to create another vertex.

    This is from the docs:

    "You can edit the polygon's shape directly by holding down the shift key as you move the mouse over an edge or vertex in the Scene view. You can move an existing vertex by shift-dragging when the mouse is over that vertex. If you shift-drag while the mouse is over an edge then a new vertex will be created at the mouse location. You can remove a vertex by holding down the ctrl/cmd key while clicking on it."

    Hope that helps!
     
  3. AngryCSharpNerd

    AngryCSharpNerd

    Joined:
    Jul 11, 2012
    Posts:
    18
    Thanks! That worked!
     
  4. Chris-Park

    Chris-Park

    Joined:
    Jan 25, 2014
    Posts:
    1
    Thanks a lot.
     
  5. xirb22

    xirb22

    Joined:
    Feb 18, 2014
    Posts:
    1
    For some reason this doesn't work for me, when I press shift I can't drag/create vertices, so I can only edit the collider using the XY values, any suggestions?
     
  6. Engidia_EduardBosch

    Engidia_EduardBosch

    Joined:
    Nov 14, 2013
    Posts:
    25
    It happens the same to me. I cannot add a vertex when I drag from an edge. Anyone knows if this happens only in the last version?

    I have Unity 4.3.4f1

    Thanks
     
  7. Yesitsdave

    Yesitsdave

    Joined:
    Mar 19, 2014
    Posts:
    9
    If your inspector is in debug mode, I've noticed you can't add or edit vertices. This may be the problem.
     
  8. Enpire

    Enpire

    Joined:
    Mar 25, 2014
    Posts:
    1
    Check the scale. It's possibly related with too large collider size. Try to zoom one of the edge. Or try to create new GO with 1:1:1 scale and add new Polygon Collider.
     
    Savidiy and samana1407 like this.
  9. iMagesBlues

    iMagesBlues

    Joined:
    Mar 18, 2013
    Posts:
    75
    Try to place your GameObject at z = 0 before creating new vertices. This worked for me.
     
    Arktnels likes this.
  10. WesRast

    WesRast

    Joined:
    Dec 18, 2013
    Posts:
    2
    This was precisely my problem. I'd left the debug mode on in the inspector, which for some reason won't let you edit polygon collider 2d components in the scene view. Definitely should be a bug.
     
  11. bblanque

    bblanque

    Joined:
    Sep 27, 2012
    Posts:
    4
    I just had to zoom A LOT to add the vertices, hope someone finds this helpful.
     
  12. Gunzaspawn

    Gunzaspawn

    Joined:
    Jan 21, 2015
    Posts:
    1
    @bblanque: Thanks! i couldn't find the answer to why i can only use the end points of my edge colliders and why i'm not able to create new vertices by holding shift and clicking. your answer worked for me too, although, it still feels like some kind of bug, because like you said, i had to zoom in an absurd distance. it's not a perfect fix in the sense that it's just obvious something is wrong (and it's a bit of a time waste)... but in the end, it worked, so bravo!

    ***edit: i had my background image scaled to 100 on y and x, as soon as i scaled it back down to 1x1 the function worked as it should.
     
    Last edited: Jan 21, 2015
  13. Dois

    Dois

    Joined:
    Feb 15, 2015
    Posts:
    7
    Thanks, that was the problem.
     
  14. u-i

    u-i

    Joined:
    Nov 11, 2014
    Posts:
    5
    Same problem here. I had to scaled to 100 on x and y and it worked.

    Thx for the advice guys!...
     
    robert-lugg likes this.
  15. mayanphsyco

    mayanphsyco

    Joined:
    Aug 12, 2014
    Posts:
    3
    I'm not sure if this goes in the same thread, but it's along the lines. Does anyone know how to make a hole in the collider? For example, a ring collider, as if only the circle's border acted as a collider, but not the inside.
     
  16. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    You cannot manually create an extra path for your polygon collider (that in turn will create the ring you hoped for).
    But if your sprite is a ring shape image, the default polygon outline generated by the polygon collider 2d component should be a ring shape collider.
     
  17. mayanphsyco

    mayanphsyco

    Joined:
    Aug 12, 2014
    Posts:
    3
    Thanks, I noticed. The problem is the ring (and other abstract shapes) are a type of thick border for various platforms, with a "floor" fill, which is also part of the sprite, so it takes it as a whole and makes no holes. I ended up making a ring sprite and copying and pasting (didn't know u could do that) it's collider to the other game objects.
     
  18. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    850
    @Kuan I was looking at this this morning, and this creates holes in PolygonCollider2D just fine (no idea if this is new since August, first time I've tried it):

    Code (csharp):
    1. polyCollider.pathCount = 2;
    2. polyCollider.SetPath(0, outsidePoints);
    3. polyCollider.SetPath(1, insidePoints);