What are the best practices for collision handling, performance-wise?

Disclaimer: I am using unity 5.x , doesn’t change anything in this question that would apply to a newer version.


What is the best method (taking performance into account) for checking collision of static areas (parts of a 3D map) vs dynamic objects like actors , props and alike (The 3D map is a series of static meshes that get loaded by chunks in and out based on the viewer’s position.

  1. Do i create some sort of “Cover-all” that encapsulates the 3D map as a collider? as in, a continuous collision model?

  2. Do i just wrap bounding boxes around the maps walls and floors and set each bounding box as a box collider?

OR do i just off-load everything to a C written plugin and just do a simple AABB test for different bounding boxes within the vicinity of active actors? (using method #2 but outside unity)

This is a “Best practice to a given case” question, so if the answer is, check in profiler and don’t do per-optimization, good, noted (You guys love giving those answers).

Thanks in advance for any pointers on how you people handle such a case.

unity physics best practices - Google Search results:

Good video , Thank you.

The video above addresses physics in general but not the question i have posed in particular. I will keep this question opened as i am looking for more answers addressing this question specifically and not unity’s physics engine as a whole.

From what i understand watching this video; even for a simple bounding box intersection, when using unity, we have to use the physics engine and all the overhead its coming with, so , you are marrying into it and having to worry about timing and garbage collection and what not; for something as simple as collision test, once using it, you have bought the farm…

I will test and profile but it seems like for me, especially for using an old-version, maybe offloading it to a plugin that only checks very basic cube intersection is the best case for me.

There’s some big tradeoffs here.

Unity’s 3D physics is PhysX. It’s a pretty well optimized general purpose physics engine. The version in Unity 5 is going to be slower than the one in later Unity versions, but it’ll still be good enough that it’ll be hard to match the performance for general purpose physics.

If all you need is AABB checks (ie. everything that collides is an axis aligned box), then writing your own physics system could very well be a lot faster and simpler.

I don’t know that writing it as a C-based plugin is the necessary. A struct-based data-oriented approach should achieve pretty much the same kind of performance.

Well, a script based data does mean C#, which means, “Safety checking” every “Instruction”, sorry for quotation marks, its just its not safe and its not using actual instructions.

And if we are talking about performance here, a C# script for it, may as well be shooting myself in the foot, But thanks anyway, noted.