Search Unity

is this still the case? sphere collider are more effecient than cube collider?

Discussion in 'General Discussion' started by toto2003, Apr 24, 2014.

  1. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
  2. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Its very likely to be still true (by that I mean it is but I'm too lazy to write a test to prove it). But the chances that you are doing something where the difference would matter are slim.
     
  3. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,363
    Yes because a sphere has 1 side whereas a cube has 6 sides.
     
  4. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    AFAIK none of them have any faces but instead are just maths, with the sphere it probably just does some fanciness with the radius and whatnot when the cube is more complex (And the capsule as well).
     
  5. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,967
    Spheres probably check for the distance towards the center, if it's less than radius then it's colliding.
    And cubes check if the point is between min and max bounds, for x, y, and z axis.

    Are you going to do many collisions per frame?
     
  6. primaerfunktion

    primaerfunktion

    Joined:
    Jan 16, 2012
    Posts:
    98
    What? I had no Idea. I'm going to test this tonight, cause the thing I'm working actually needs a lot of colliders.
     
  7. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Spheres/circles have pretty much always been faster than rectangles because, as said, you can just check the distance from the center of the sphere vs its radius... rectangles can take up to 4 tests to see if there is an overlap, or even more complicated when it rotates.
     
    Meltdown likes this.
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Right...unless math itself changes fundamentally somehow, sphere/circle colliders will always be faster than cube/box colliders, forever.

    --Eric
     
    Jaqal and Xaron like this.
  9. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    *ponders if a signed distance representation would help the poor cubes and other non-spherical objects*
     
  10. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    There was a technique used on GPU driven particles to speed up collisions between cubes, which worked essentially by treating each edge of the cube as a capsule, so you basically ended up with a rounded-cube collision "mesh". Capsules are much easier to do collision checking than cubes also (though not as much as spheres), but it was pretty efficient compared to actual box collision.

    The obvious drawback is that not all cubes have rounded edges, and maybe rounded edges won't work for your needs. Might be worth a test with compounded capsules against the cube collider to see what wins out though. The GPU method was pretty optimized at a shader level though, so maybe the overhead of having 12 capsules will be worse than having the one cube if you just do it the 'easy' way.

    Cheers
     
  11. MarkrosoftGames

    MarkrosoftGames

    Joined:
    Jan 5, 2012
    Posts:
    442
    very interesting. i had never thought about it that way (or at all really). seemed like since cubes are flatter they would be easier, but this makes perfect sense now that i think about it.
     
  12. Lambastard

    Lambastard

    Joined:
    Feb 12, 2013
    Posts:
    5
    Pardon the necro, but are there any calculations or estimations regarding the actual overhead difference between sphere and cube colliders?
     
  13. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Think of it as this:

    A sphere only (in some cases) needs to check if the distance to a point is larger than radius. One check and a distance calculation.

    A box in 3D needs to check if min and max bounds are bigger or smaller than each other in all axis. Up to six checks.

    However it is not always that easy. It depends on what type of form you are check against each other. Checking a sphere vs a sphere is not the same as checking a sphere vs a box.

    With more complex forms and rotation comes more checks. Like separating axis collision detection.