- Home /
2D Physics: Can rigidbody ignore colliders if it starts inside them?
Hi, Does anybody know if it is possible to set up a 2D Physics Rigidbody to ignore Edge or Polygon Colliders if it is already inside them?
(A colliding plattform can consist of more edge colliders sequenced together, all in clockwise direction)
Thanks, Marko
Well, if it's only a specific collider, you can use Physics.IgnoreCollision.
unfortunately no, this need to be a general behaviour...
Answer by Halleester · May 03, 2016 at 04:36 AM
You could have the collider set to be a trigger at first, and use OnTriggerExit2D
to turn on the collider portion again using Collider2D.isTrigger = true
. If it still needs to collide with other objects while in the zone, you could create another layer to temporally place it in, which could collide with other objects while ignoring the starting collider. You can change what layers collide by going
Edit --> Project Settings --> Physics 2D
The second method might work better for what you are looking for, but the first one is great if you need specific layers for something mechanics-wise.
Answer by Outliver · May 02, 2016 at 06:27 PM
You could do a raycast from the collider's center into the direction of the GameObject's center. And then see if you hit the the collider or the GameObject first.
In fact, there are many ways you could check if your GameObject is within or out of your collider.
Thanks for the reply, but this would only work for convex polygons. If a polygon is concave it will fail very easily.