- Home /
Optimization (2D) - Box Collider vs Circle Collider
Hello, I am almost done with developing a mobile game. Now it's time for optimization. There are a lot of places where I have used 2D Box Colliders but is it true that Circle Collider is more optimized?
Thank You
Answer by GarBenjamin · Aug 23, 2014 at 02:19 AM
According to this post it is:
http://forum.unity3d.com/threads/capsule-vs-box-colliders.34254/
Fastest to slowest...
capsule sphere box
Personally, I don't understand that. In my mind nothing should be faster than a simple overlapping rectangle (or cube) collision checking routine. But the test results definitely show box as being the slowest. Maybe it is something the graphics card itself can do these days.
Anyway, I doubt it would be worth the effort converting your entire game to use sphere colliders. Considering rectangles and cubes are the slowest method this aspect should be very fast in all cases. I think the biggest gains for collision checking would come from simply layering your objects and only allowing certain sets of objects to collide with other sets (enemies likely would not collide with other enemies or with powerups and so forth).
I would imagine the thing you may not be considering is the possibility that the boxes have different rotations. I believe that makes the check a good deal more difficult than a check where you can assume that the edges are parallel with the axes.
Why would anything be faster than circle/sphere? The only thing to check if centers of those colliders are closer than sum of their radiuses.
For square/cube there is a lot more going on and they are rotation dependant unlike sphere/circle
Answer by juanitogan · Oct 04, 2018 at 08:32 AM
An answer specific to the 2D world can be found here (spoiler: circle is fastest):
https://stackoverflow.com/a/42029708/680464
Info on CapsuleCollider2D, however, is not included and I would be interested to see if it still outperforms box in the 2D engine (since it is now competing against a 4-corner box instead of an 8-corner box). No info on edgeRadius either (which, basically, on a box, turns a box into a capsule stretched two ways).
Your answer
Follow this Question
Related Questions
Is Physics2D BoxCast accuracy influenced by tranform.scale ? 0 Answers
Platformer2D Player sticks to platform corners 0 Answers
Inaccurency BoxCast2D,Inaccuracy BoxCast2D 0 Answers
Rigidbody2D is kind of flying instead of falling when the child box is colliding 1 Answer
Some BoxCollider2D don't get hitted by no apparent reason 1 Answer