1
\$\begingroup\$

Sprite A: Box Collider 2D and Rigidbody 2D.

Sprite B: Box Collider 2D.

Both sprites have a Sprites/Default material with Pixel Snap enabled. The textures being used are set to Truecolor Format and Point Filter Mode. No Mip Maps and 1 Pixels Per Unit (higher PPU seems to make the issue more obvious, but lower value does nothing but scale the problem down).

I put Sprite A above Sprite B, hit play. I see Sprite A fall into Sprite B and hover slightly above it. I think this is horrible, so I look it up. I find I can lower Min Penetration For Penalty to help.. but not fix.. this issue. It's barely noticeable now.

After a while, I noticed Sprite A sometimes overlaps Sprite B briefly during collisions. I can't seem to find a clean fix to either of these issues.

Is Unity's physics engine just not designed for the level of accuracy I'm wanting? It seems the whole way the physics engine works is by allowing overlap (minPenetrationForPenalty) before pushing objects out of each other. I've been coding for many years as a hobbyist, so no professional experience, but this seems.. wrong. Are there options that don't involve overlapping of objects?

Thanks for any and all help.

\$\endgroup\$
  • \$\begingroup\$ What happens when you change the pixels to units to 100? Having a low pixels per unit actually increases the workload on the physics engine... This may be what is causing the overlapping. If you need your sprites to be larger than their default size, then I suggest manually changing them in an image editor as opposed to reducing the pixels per unit in unity. \$\endgroup\$ – Savlon Aug 7 '15 at 23:07
  • \$\begingroup\$ Higher pixels to units seem to make the problem MORE visible instead of the other way around. It's less noticeable the lower the pixels to units is. I'm using 16x16 pixel sprites/tiles. I'm going for a classic NES style side-scroller, visually and physics wise. For testing, I've scaled time down so I can see what it's doing.. and it's VERY easy to see for 3-5 frames objects intersect and slowly push each other out. \$\endgroup\$ – Mythics Aug 8 '15 at 1:55
1
\$\begingroup\$

You could try changing the collision detection to Continuous or Continuous Dynamic. See the Unity Manual: Rigidbody for further info.

\$\endgroup\$
  • 1
    \$\begingroup\$ Pixel Per Unit seems to change scaling as expected without doing much to help. Interpolate smooths out rendering, which is super important to me, but didn't have much to do with the issue I was seeing. Setting Sprite A to Continuous collision detection seems to fix it no matter the other settings. Thanks mate! \$\endgroup\$ – Mythics Aug 8 '15 at 13:08
1
\$\begingroup\$

This will occur in Unity, if a GameObject is too small. The colliders will end up being either too far or overlapping, as the physics get unstable if the GameObjects are too small.

Try making the gameobjects much larger (change the pixel per unit size), and you will see that it will more than likely fix your problem.

\$\endgroup\$
  • \$\begingroup\$ Pixels per unit set at 100 made little to no difference. I can even slow down the time scale and see it penetrate to like 4 pixels deep in a 16x16 pixel sprite. It's like instead of forecasting the collision and preventing the overlap, it just lets it happen and "pushes" the object back out slowly over multiple frames. \$\endgroup\$ – Mythics Aug 8 '15 at 1:15
  • \$\begingroup\$ I have experienced the exact same issue, and adjusting the size of my sprites solved it. Not saying this is what your problem is, but it sounds like it is to me. \$\endgroup\$ – jgallant Aug 8 '15 at 1:31
  • \$\begingroup\$ I've tried scaling up and down both to extreme levels. 1 pixel per unit looks far better than 100, but it's just scaling the problem to a level that makes it harder to notice. Thanks for the help though, definitely up-voting for your effort if nothing else. \$\endgroup\$ – Mythics Aug 8 '15 at 1:52
1
\$\begingroup\$

Sounds like a simple rigidbody setting. Change from interpolate to extrapolate, or vice versa.

http://docs.unity3d.com/ScriptReference/Rigidbody2D-interpolation.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.