- Home /
How to avoid gaps between 2D physics objects?
Here I have a project with some 2D physics blocks (objects with a non-kinematic Rigidbody 2D component). As you can see, they have these gaps between them and the ground/other objects.
You may also be able to see from this image that I've shrunken their colliders. As I was doing this, I found that even if I could close the gap between the blocks, a gap would remain between the blocks and the ground. If I shrink the colliders enough for there not to be a gap between them and the ground, then they are inside each other.
This makes me think there's a "skin" thickness setting or something on the physics, but I can't find any for 2D physics. I've tried adjusting the mass and gravity. Neither fix it, though high gravity makes everything jitter. How can I best solve this problem? Thanks!
You can reduce the collider size on the box until it fits closer, or try changing the $$anonymous$$imum penetration distance for forces in the physics settings
@Josh707 : You may have missed the paragraph about changing the collider size, but I've tried that I can either make it look ok on box-to-box, or box-to-ground, but not both. What I need is to be able to make it collide on the collider edge, and not on an invisible bubble. Also, I mentioned this penetration setting doesn't seem to be in 2D physics settings in my final paragraph. It is in 3D physics, but that setting does not affect 2D physics at all from what I'm able to see.
Thanks for your thoughts.
Ah sorry, I haven't downloaded the newest version with the 2D tools yet so I wasn't sure how different it was. It's weird that you can't get the collider size to be properly sized though, hopefully someone else can help you!
What about if you shrink the collider on the boxes to make them good from box to box? Then since you only have a problem with the ground, adjust the ground collider to find your happy place. $$anonymous$$aybe you've already done/thought of this
@highpockets I may end up having to shrink the ground collider, but since I'm using different pieces of ground of different sizes to build levels, that's pretty annoying to have to deal with on a larger scale. Also, this skin thickness issue makes it impossible to set collision with the player to what I actually want it to be for both physics and non-physics objects. For instance, I make the collision smaller for non-physics objects (which my player is), and that fixes the gap between them and physics objects. However, then the player sinks into other non-physics objects.
Answer by Diego-Machado098 · Feb 11, 2016 at 01:49 PM
Just in case someone stumble upon this: Decrease the 'Pixels per Unit' property on your textures. This will make Unity show sprites bigger and those little gaps we'll be filled/unnoticeable.
Don't forget to adjust the gravity accordingly. (menu: Edit > Project Settings > Physics 2D)
I'm using Pixel Per Unit: 1 and Gravity: -981
Answer by Reispfannenfresser · Mar 03, 2020 at 03:59 PM
Just in case some more people stumble upon this:
The gap is determined by this value. Changing it to 0.0001 makes the gap unnoticeable, but may also cause some collision wonkiness.