What is cheaper? Sphere collision checks or box collision checks?

Hello,

if I have the choice to use a box collision object or a sphere collision object, which one should I use? For my understanding, sphere collision could be more expensive. To check collision with a sphere, you have to use the square root for the distance from the sphere origin. For a box it’s only a if-else. But I don’t know much about this. What’s cheaper?

Thank you,

Thilo

2 Likes

Box is cheapest. The simpler the shape (polys), the cheaper.

Wouldn’t Sphere Collision checks be cheaper. I don’t think they’re checking the square root of the distance. A squared distance check should suffice. But for the box, wouldn’t it require multiple conditional checks? On second thought, that would work for sphere to sphere collision checks. I’m not sure about other scenarios.

Negligible difference, go with what is most accurate.

@Bits360 Much small differences can make a huge difference :wink: It’s usually not only one collision object…

1 Like

Gotcha. Mostly depends on application. Just dont use convex collision if your having many of 1 object.

The cheapest collider is a Sphere, followed by Capsule, Followed by Box (Which are Mathematical)
Then there are the non-primitive forms of collision, like Convex, and Non-Convex(Complex) collision (Which are Geometry based)

Spheres are the cheapest form of collision, because the mathematics involved in determining if an object is colliding with a sphere, it’s actually done solely based on distance to the centre. Sphere collisions (Despite how they might look in engine) don’t have any polygons. They are a mathematical concept, a primitive.

Capsules are similar, except the distance is checked against a line inside the capsule that represents the inner most portion of the shape. So there is a slightly larger degree of complexity. You’ll notice that when you control the parameters of a capsule, you’re only controlling the length of that line, and how far the surface of the capsule is from it.

Cubes/Boxes are the most complex of the 3, because there is simply more complex mathematics at play. Nothing too substantial but it is certainly heavier. The nature of boxes allows them to be non-uniform. Then there is orientation to consider. So there are just more layers to the calculation.

Next up the list is non-uniform convex collision. It has all the properties of the box, but with even more to evaluate and calculate. The expense is generally not too significant, but building your collision from Primitive collision is SO much cheaper than using generated collision.

Finally, we have Non-uniform non-convex collision. Which is so wasteful it’s basically never worth using. It’s always better to use multiple primitive shapes, and build up your collision with them.

For the record, it is ALWAYS good to know these things. As @ThiloN1987 stated, you can end up in a situation where you need thousands of collisions, and only the cheapest will do!
You should never disregard something as important as optimization if you want to work on games. As a hobbyist, something like this isn’t as consequential. But lag spikes, or poor performance will prevent your game from being launched on platforms with high standards (Basically all consoles).

Despite significant technical advancements in game development technology, things like collision are still very important things to consider. They are pivotal for optimizing physics based objects, constructing proper collision for complex meshes, and ensuring your game is responsive and well tuned.

[Update]: Per @AntiGravity 's request: All collision calculation is performed by the CPU, regardless of whether or not you are using Primitive, Simple, or Complex collision.

11 Likes

No worries! I know it’s one of the hurdles with game Dev, so I just wanna make sure the info is out there :slight_smile:

That’s a great question. Sadly it’s not one I could confidently answer. But I’ll ask a colleague of mine and get back to you.

[UPDATE]: In UE4 all collision calculations are performed by the CPU. I hope that helps!

1 Like