# Is Collider.contactOffset supposed to affect BoxCollider? (Trying to get smoother collisions)

I am experimenting using boxes as colliders between vehicles and it is otherwise working ok but the boxes often align with each other which does not feel always good when racing. More explanation here: Reddit - Dive into anything

I was thinking that maybe using a higher value for contactOffset would help this issue and allow the colliders to gradually increase the force they generate when getting closer. But it seems that the value has no visible effect. The colliders can get just as close to each other with the default 0.01 and higher values (even with extreme value like 1.0). Any idea why? Is it not supposed to work with BoxCollider or is there some internal max value?

Any other ideas to solve the actual problem? (What I might try next is combining different types of colliders but ideally, that would not be needed).

Indeed, and that’s because of how the contact offset value is used by 3D physics. From the docs:
“Colliders whose distance is less than the sum of their contactOffset values will generate contacts”

What the documentation says is true for 2D and 3D, however, there is something missing and that’s the “de-penetration” part. 2D and 3D work in different ways in this regard. Check this

From that thread: “The distance at which this maximum force is reached is the restDistance, because at this distance two shapes stacked on each other will reach static equilibrium and come to rest.”

Basically, the contact offset does not affect de-penetration in 3D. BTW you can’t set the “restDistance” from the editor.
In my opinion, this is THE advantage of 3D physics over 2D physics.

You can always use collisions callbacks (OnCollisionXXX) and cheat a bit. For example, when two cars align with each other side by side (box against box), the collision involved will register 4 contacts (the same happens with a box vs flat ground). If that happens, then apply some force in order to separate them.

BTW, the first video (reddit) looks fine to me.

Thank you for the information! Yes, it seems I cannot achieve what I would like with contactOffset and restDistance.

I don’t think you can set it by scripting either? Also contact offset seems to be modifiable only by scripting, not in inspector. (Unless I have missed something)

Something like that could be a solution, yes, but I’m afraid it might be too heavy to do that correctly.

It is quite ok, but the main problem comes in situations where cars are next to each other and start pushing each other. It feels unnatural and rigid, especially if one is somewhat (like half-car) ahead of the other. With capsules, everything is more fluid and dynamic, but for more serious non-arcade racing, it also feels unrealistic when cars roll so easily.

That’s right.

You can’t modify this offset in the inspector, only through code. The collider contact offset field can be modified (technically speaking) but that doesn’t mean it will affect anything (low level stuff). In my experience, changing this value does nothing (only the “default contact offset” matters).

Here’s a very simple example:

``````void OnCollisionStay(Collision collision)
{
// i'm using just a tag filter
if(!collision.gameObject.CompareTag("Car"))
return;

// Here is where things might go wrong, i guess you could test it and see if it works
int count = collision.contactCount;
if (count >= 4)
{
for (int i = 0; i < count; i++)