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?