0
\$\begingroup\$

I'm learning 2D Unity and am experiencing a very strange problem. When I have 2 objects both with Box Collider 2D and a RigidBody2D, and one of them is set to be static so it doesn't move, the other one floats just above it. Here's a screenshot so it makes sense Physics are seemingly broken

The red box is the one that is not static, the black one is. The red one should sit atop the black one but is floating above it for some reason. I have no idea why. The hitboxes should be right, here are images of them

hit box

hit box

What can be done?

\$\endgroup\$
2
  • \$\begingroup\$ When you place the red box higher, does it fall down? \$\endgroup\$
    – Philipp
    Feb 27, 2020 at 17:40
  • \$\begingroup\$ @Philipp yes, it keeps falling till it reaches that point and just floats right above it. If I drag it to the side it falls off. \$\endgroup\$ Feb 27, 2020 at 18:06

1 Answer 1

1
\$\begingroup\$

This looks like the default contact offset:

Colliders whose distance is less than the sum of their contactOffset values will generate contacts. The contact offset must be positive. Contact offset allows the collision detection system to predictively enforce the contact constraint even when the objects are slightly separated.

This contact offset is important, because it gives the physics system a little buffer zone to do its work efficiently.

If the offset is visible at the scale you're working at and proving distracting in play, you can slightly reduce the size of the colliders to compensate.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .