# Collision intepenetration and objects getting stuck (Unity)

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.

• 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.

• Does this mostly, or always occur with high-speed collisions? Your image shows some objects interpenetrated from opposite sides, which could be squishing the object in the middle. Does this occur with 2 objects, or does it require more than 2? Feb 27 '12 at 15:46
• It occurs between 2 objects, but once interpenetrated, they won't come unstuck, so if a third one happen to smash into them, it can become stuck as well. For the speed, I mention it above, but to clarify, it is so that the car crosses the screen in 2-3 seconds. So it is relatively high, but nothing shocking. We are not talking of a bullet here.
Feb 27 '12 at 15:55
• The fact that the interpenetrations become more rare, or less deep, when the step times are reduced suggest that it has to do somewhat with the speed of the colliding objects. Unfortunately I don't have experience with Unity's physics engine, but many physics engines will allow you to increase the priority of collisions with certain objects. You may also be able to change the way collisions are handled through some global setting that calculates collisions with a TOI (time of impact). Using a TOI should prevent this kind of issue, but is a more expensive way of handling collision detection. Feb 27 '12 at 16:35
• You should put your solution as an answer and mark it as accepted. Feb 28 '12 at 21:22