- Home /
2 collisions/colliders not working properly (gap between the 2 objects that collide)

So here's a very basic example, I'v 2 sprites, with one box collider 2D each, and the upper one has a rigidbody 2D. So normally the upper one should fall one the lower one and that's all. But if you look at the image, there's always a gap between the 2 sprites. Is there something I do wrong, something that I didn't set correctly or is there a sort a bug with Unity that you have too?
I've also heard 2 solutions to partly fix it, the first one is to reduce the size of the colliders, so the colliders are smaller than the sprite and the "void" between the object is filled with the sprites, but it's only possible for basic colliders shape like box colliders or set the pixel per unit to 1, so that make is 100 times bigger and there's no more gap, but doesn't it make the game very laggy to make everything 100 times bigger or cause physics bugs with a gravity of 981 instead of 9,81?
remove the sprites and share with us a screenshot so we can see the "void" between the box colliders, the sprite is just a graphical representation and nothing has to do with the box sizes dont change the pixels per unit and almost 100% is not a unity bug
An another thing to keep in $$anonymous$$d is the side effect of the contact offset of the physic engine.
If it's your problem you can reduce all your collider size by this value (or half this value). You can even do it programmatically.Default Contact Offset Set a proximity distance value for colliders to be considered in contact, even they are not actually in contact. Colliders whose distance is less than the sum of their contactOffset values generate contacts. This allows the collision detection system to predictively enforce the contact constraint even when the objects are slightly separated. Caution: Reducing this value too far could cripple Unity’s ability to calculate continuous polygon collisions. Conversely, increasing the value too much could create artifacts for vertex collision.
i have never seen the contact offset so big by default, it looks more like he imported sprites not fully cropped with free space in the borders, dont they?
You are probably right but its hard to say with just that screenshot. I will rephrase my previous comment.
Your answer