x


Performance of Physics.Raycast

Does anyone know what the relationship is between the performance of Physics.Raycast, and the amount of triangles in a MeshCollider? Will it take longer for more polygons, or is Unity doing some fast, octree culling behind the scenes?

I ask because I have a large terrain with a MeshCollider attached to it, and use Raycast to detect collision with it. However, most of the terrain will never be touched, and I was wondering whether it would be worthwhile to split then mesh into touchable and untouchable submeshes and only attach the MeshCollider to the touchable bits.

The terrain mesh is around 30-40k triangles, and this is on iPhone. And yes, we have determined that this is important for performance.

Thanks in advance.

more ▼

asked Dec 22 '09 at 06:11 AM

Peter Alexander gravatar image

Peter Alexander
931 5 6 23

(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Very large mesh colliders do slow things down, as the physics must internally check against every triangle, sort of - by what ratio it is slower, I am not sure. Of course there are lots of internal optimizations, but you'd have to read up on Physx here

The best way to find out of course is a simple test - create one mesh collider with 40k triangles, and then create 1 with 4k, and check out the performance difference in unity 2.6 with the profiler.

If you can, you might also try using a compound collider with a bunch of box colliders, unless the detail in this terrain is exceptionally important.

I used the CharacterController (which internally does some raycasting) for ExtremeSledding on the iPhone, typically on terrains of ~5k triangles. If the terrain got to around 10k, performance was horrible. I can't imagine you will have much luck with 40k triangles on the iPhone except in the simplest of cases.

It goes without saying, but it would be worthwhile to split the terrain simply for the purposes of culling, if that makes sense in your game. (I assume you already are, and simply kept a single mesh collider?). At around 12k triangles on a 3G (not 3gs...) performance starts to sag a bit for me.

more ▼

answered Dec 22 '09 at 05:31 PM

Brian Kehrer gravatar image

Brian Kehrer
2.8k 9 11 50

(comments are locked)
10|3000 characters needed characters left

For a test, I'd want to have the same number of collision triangles in the scene but have them in more than one collider. That'll tell you if Physx is doing any internal optimization like Bounding Box checking. I hope that it is. :)

more ▼

answered Dec 22 '09 at 08:03 PM

Ben Throop gravatar image

Ben Throop
259 5 9 13

(comments are locked)
10|3000 characters needed characters left

I know I'm in late, but you can also create a simplified version of the path you want your player to be able to take through the terrain and use that as collision. Turn off the Mesh Renderer and group it with your visible polygons.

Best Fishes,

Spence.

more ▼

answered Jan 30 '10 at 10:25 PM

spencer lindsay gravatar image

spencer lindsay
207 8 9 22

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Jul 12 '11 at 05:15 AM

vivek2012 gravatar image

vivek2012
-39

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1877
x1529
x1363
x662

asked: Dec 22 '09 at 06:11 AM

Seen: 5619 times

Last Updated: Jul 12 '11 at 05:15 AM