# How to resolve push block physics in a 2D side scroller puzzle

I've been working on a 2D tile-based side scroller puzzle game in Unity with obstacles such as doors, keys, fans, portals, etc., but one type of obstacle, push blocks, is giving me some issues. Here is how it is supposed to work:

• The player (an certain other obstacles) can push the block from either side, and it should move smoothly until it is either blocked by another obstacle or there is no ground beneath it
• If it is pushed off an edge, it should fall into whatever hole is there, even if it is a snug fit. (left picture)
• The top of the block should be flush with other blocks or surfaces when they are at the same level of height. There are no slopes in the tileset, so this would happen often. Motion across the combined surfaces should be smooth, with no way to wiggle between adjacent blocks. (right picture)
• It must be able to respond to other forces in the game such as fans and gravity switches.

I have been using Unity's built-in physics engine, which has worked great for all other components of the game, but sometimes allows blocks to jump over holes, and sometimes blocks get stuck between other blocks when they shouldn't, so I have tried abandoning Unity's physics and made my own. It just made the rest of the game more glitchy and still failed to resolve the block problems.

If I change just the way the blocks physics work, I may be able to lock its position to a grid, where it cannot be left between tiles. That way I could get the more snug collisions to work. If I did this though, it would cause problems with the rest of the interactions. A floating block with a fan underneath it bounces around too much to be locked to a grid. Does anyone know a design that would allow all these requirements of be met?

• Physically, when determining how an object falls, you need to look at the center of mass of the object. More than likely your center of mass is being positioned at the center of your cube. Thus, as soon as more than half of the block is over the hole, the block will start to topple over and not go smoothly down. One solution may be to move your center of mass to the edge of the block. For instance, if you are pushing your block to the right, make sure your center of mass is at the left most position. docs.unity3d.com/ScriptReference/Rigidbody-centerOfMass.html Commented Mar 3, 2016 at 22:12
• That part isn't a problem since I disabled rotation on the block, so it already waits until 100% of the base is off the edge. The problem is that when the hole is only barely big enough the other side catches it before it has a chance to drop. Commented Mar 3, 2016 at 22:27
• Ah ok. Can you decrease the collider then slightly? Commented Mar 3, 2016 at 22:33
• I've tried that, and it allowed the hole to catch the block sometimes but not always. I would have to shrink it quite a bit for it to work 100% of the time. And if I did shrink it, it would create more problems trying to slide things over it like in the second picture since it is no longer flush with land and there are gaps between blocks. Commented Mar 3, 2016 at 22:45
• It isn't simply too big time steps? Such that in one frame the block is on the left side of the hole, the next time step the block is on the right side of the hole? If so, consider decreasing time step or forcing it back to the hole if it passes over it. Commented Mar 4, 2016 at 5:29