I am having what is probably a newbie problem with Unity, but for the life of me, I can't find a decent solution to it. In short: my rigid bodies collide, but sometimes, they interpenetrate and stay stuck.
I am looking for a solution that would either 1- stop the interpenetration from even happening 2- or at least eject the bodies to 'unstuck' the collision.
By making the physics fixed step 0.01 instead of the default 0.02, I can avoid some of the interpenetration. However, that hardly sound like the proper way to fix this problem.
Here is a screen shot of the bodies colliding. The car on the right is shown completely and you can notice that the ones behind have penetrated the others to some extent.
To give more information that could be relevant:
There is no gravity
All the objects have rigid bodies
Their sizes are 3.5 x 6.8 and they are moving at 8 to 50 m/s
Each object has a conpounded collider made up of 3 box colliders
If I change the fixed step to 0.01 there is a lot less more interpenetration (as I mentioned). Other physics settings do not seem to have any effect
The object is moved by setting its velocity in the FixedUpdate function with rigidbody.velocity = XYZ until there is a collision, then there is no more processing done in FixedUpdate at all. I detect the collision with OnCollisionEnter and set a flag.
I haven't set any collision material, but I can't see that being a factor?
Solved
Thanks to everyone who helped me with the issue.
There were a few factors in play. First, there was the scale. What I did to figure this one is create an empty scene and put 2 cubes in there. I varied the size and position of the cubes (from 68x35 to 0.65x0.35 for size and the position by factors or 10 as well) and attached a script to move them, with variation in speed by factors or 10 as well. So all else being equal (same size on the screen and time to cross it), the size of the objects elected a different response to collision: big object got interpenetration, small ones none. I am not familiar enough with Unity to explain the cause of that, but it is reproductible.
A possible second factor was the shape of my colliders and how it may be possible that they screwed up the ejecting part. The colliders I had were not overlapping, so I simplified them to 2 boxes in the shape of a cross.
Finally I was setting the position of the objects manually in FixedUpdate and that caused some problems with interpenetration at lower scale (at higher scale, it didn't appear to matter). I changed that to work with the body velocity and it helped.