Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does changing Physics.defaultContactOffset have an important impact on performance?

Tags:

As usual, the documentation lacking some information we have to gather somewhere else: Physics.defaultContactOffset.

Physics.defaultContactOffset is used by the collision detection system to predictively enforce the contact constraint.

Unity explains you should use 1 unit = 1 meter for physic simulation.

I needed a lot of small spheres and cubes: 10cm width. Thus 0,1 "unit".

What they dont say is that when you're working on a small scale (I'm using objects of 0,1m width = 10cm) you have to change Physics.defaultContactOffset to a smaller value than the default one.

Hence my question: is Physics.defaultContactOffset important for calculations, i.e. if I change this to a very small value, does it have a negative impact on performance?

I have to change it from 0.001 to 0.00001 to get an acceptable collision detection system and I'm worried about a negative impact on performance.

like image 734
Olivier Pons Avatar asked Nov 01 '18 10:11

Olivier Pons


1 Answers

From Unity3D documentation on Default Contact Offset:

Use this to set the distance the collision detection system uses to generate collision contacts. The value must be positive, and if set too close to zero, it can cause jitter. This is set to 0.01 by default. Colliders only generate collision contacts if their distance is less than the sum of their contact offset values.

So we can assume the physics engine is calculating distances between colliders and checking if the distance counts as a collision or not. I don't think it matters so much for performance as the calculation is done anyway.

With all this being said, Unity3d physics engine doesn't really do well with tiny objects, so it's better if you scale the spheres up to 1 unit, and scale everything else to compensate. You will most likely run into issues with these tiny colliders.

like image 122
Dave Avatar answered Nov 15 '22 05:11

Dave