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. Dismiss Notice

How To Solve This Collider ?

Discussion in 'Editor & General Support' started by CoolCosmos, Aug 4, 2020.

  1. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    I have a sprite spider. I want to add spider a collider which will cover its around almost perfectly. But when i add it a polygon collider, its collider becomes like the way in screenshot. I tried to solve it by vertex by but it doesn't seem a good way to me. Do you have any ideas to cover it with a collider ?
    image131313.png
     
  2. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    Can i fix it by those settings ?

    image4124213.png
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
    You can edit the polygon collider by clicking "Edit Collider" button on the collider component.

    However, such a complicated concave collider will not have good performance. Does the collider really need to be perfectly aligned with the sprite for your gameplay? Often a simpler collider will behave just as well without sacrificing so much performance.
     
  4. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    I wish, we would have different type of colliders to solve this kinda problems. Triangle collider might help me...
     
  5. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    Why doesn't Unity allow us to add vertices or change vertices of current colliders like box, circle, etc..? If we could, it would be easier to implement the collider shapes that we need...
     
  6. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,697
    The colliders you mentioned (box, circle) have extremely simple and extremely fast collision detection. If you were allowed to change vertices that would no longer be the case.

    Think about a circle collider for example. Rather than looking at any vertices or anything, the collision detection is as simple as "is the distance to the center of the circle less than the circle radius". That's really fast and easy to calculate. For boxes you just need to check if the individual x y z Coordinates are within a certain range. Again very fast.

    Once you start adding arbitrary points to the mesh and you need to do some complicated algorithm to check collision, suddenly performance drops enormously.
     
    CoolCosmos likes this.
  7. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    @PraetorBlue thanks for your attention about the topic. I hope unity brings this feature soon. So we can decide what we want to do. I am going to add edge collider for each legs of spider and use composite collider to merge them all. So would that cost less performance drops ? I don't think so...
     
  8. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    Thats how to fix it by edge collider. :)

    image492834.png