Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Convert edge to polygon collider?

Discussion in '2D' started by Kaemalux, Apr 2, 2015.

  1. Kaemalux

    Kaemalux

    Joined:
    Aug 1, 2013
    Posts:
    45
    Hello!
    Is it possible somehow to convert a complex collider in another type?
    I am using 2D toolkit, but it creates meshes and in 2D it results in edge colliders: the problem is that i cannot use them properly with some other features, so i am asking if it possible to convert the collider in another one, keeping same vertex.
    Thanks in advance, have a nice day! :)

    Kaem
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,999
    Probably could make editor script for that,
    - Take edgecollider vertices
    - assign them to polygoncollider verts

    Or does it just work if you delete edgecollider, and add polygoncollider component ?
    (and you can multiselect many objects to do that for all)
     
  3. Kaemalux

    Kaemalux

    Joined:
    Aug 1, 2013
    Posts:
    45
    Thanks for the suggestion! I tried to simply add polygon collider, but it is a complex mesh (made by 2D toolkit), so it simply add a polygon fitting the shape, but totally different from all vertices i need.

    You suggested an editor script, as i am a newbie could you point me what should i do and where to start scripting. I read something on the manual, so i suppose i should use
    public function SetPath(index: int, points: Vector2[]): void;
    but actually i don't know how and where to set it properly. Could you gently give me a bit more help? ^^
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,999
    Can you show image how it should look and how it came out with polygoncollider?
     
  5. Kaemalux

    Kaemalux

    Joined:
    Aug 1, 2013
    Posts:
    45
    Sure, thanks. :)

    Here it is

    Exact collider is an edge one, built on the complex mesh derived by 2D toolkit. If i try to add a Polygon Collider 2D to the chunk, it is a simple pentagon without any consideration of vertices...

    Did you understand? ^^
     
  6. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    832
    bump

    just noticed that 2dToolKit does this, need solid colliders not these empty ones...
     
  7. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    832
    Last edited: Nov 3, 2015
    juelzsantana123 likes this.