- Home /
EdgeCollider2D or BoxCollider2D?
Hello! Im doing this 2d platformer game and i have a question about what colliders should use. They said that boxcolliders2d is better than polygon collider and edge collider2d. But building the level with many box is getting very hard with so many corners generating unnecessary collisions. The level is also very organic with many subtle angles in platforms. Building this with boxes is not really working, and I'm with that feeling that I'm doing it wrong(newbie here btw). So i experimented the edge collider 2d and the workflow was very easy and all those ghost collisions disappeared. So i read about box collider vs edge and got worried about game performance, i profiled the game the way it is now but i don't really see any difference, actually i don't really understand about performance.
So here is my questions:
Is edge collider 2d is that worse of collision for performance compared to the box collider 2d especially when i have to use so many boxes colliders to get the level flow right? Can you explain better whats really the difference.
I also would like to know if that big difference performance in physics is more of a 3d issue workflow or really a issue to worry also in my 2d context of platforming game?
Im targeting the game to pc and hopefully a console like ps4 and xbox one. No mobile. And the project im trying to do in order to specify what kind of 2d platformers i basically aiming in a game play fast paced liked ori and the blind forest.
I know that I'm very far from my goal right now, thats why I'm would love to here more experienced advice in this collision subject. Thank you very much! Cheers!
Answer by MelvMay · Jul 28, 2016 at 08:35 AM
Is edge collider 2d is that worse of collision for performance compared to the box collider 2d especially when i have to use so many boxes colliders to get the level flow right? Can you explain better whats really the difference.
You can't just say EdgeCollider2D is better/worse performance-wise than a BoxCollider2D and make some hard rule. What you can say is that a BoxCollider2D has an AABB which when it overlaps another Collider2D AABB, all four edges need to be checked for collision. If the BoxCollider2D moves, this single AABB has to be updated (in the broad-phase).
An EdgeCollider2D has an AABB for each edge which means that only a single edge that overlaps another Collider2D AABB needs to be check for collision. If the EdgeCollider2D moves however, all AABB for each edge have to be updated (in the broad-phase).
So comparing them not moving, an EdgeCollider2D is more efficient than a BoxCollider2D at detecting collisions because potentially, only a single edge needs to be checked if a Collider2D overlaps only that edge with the added benefit that it is a continuous surface so Collider2D moving from edge-to-edge don't get stuck. It doesn't however create a closed shape (there is no 'inside' to be overlapped with) unlike the BoxCollider2D so unless you use Continuous collision detection on fast-moving Collider2D, they can potentially jump through it. The same could happen with a BoxCollider2D but they are typically larger than a single line with zero thickness! Finally, and kind of obviously, using a single component has an advantage over 10s or hundreds of individual BoxCollider2D components.
In the end, the performance difference may be negligible depending on how you use it. Just worrying about performance without there being a performance issue will lead you astray.
Thank you very much $$anonymous$$elv$$anonymous$$ay for the crystal clear explanation and the tip related about worrying performance issue without an actual issue to worry about. Both insights helped me a lot really! Thanks!
Your answer
Follow this Question
Related Questions
Is it possible to have continuous collision detection with dynamic points on Edge Colliders? 0 Answers
Is there a way to apply a texture to a 2d collider? 1 Answer
Objects falling through EdgeCollider2D on the ground 0 Answers
Box Collider 2d don't collide 3 Answers
Physics2D.OverlapArea inaccurate? 2 Answers