As a budding developer, my biggest issue with Unity seems to be figuring out how to structure a game from the outset. Once the structure is in place though, I seem to do fine in getting all the systems and code to work great.
I’m struggling to figure out how to set up a game like Tetris within Unity. Using standard design, I could create the classes and the game itself without prefabs, but that seems to go against the nature of what Unity is all about. I would rather take the ‘object with components’ approach.
How would you set up Tetris within Unity? I’m using primitive cubes as the blocks that make up the shapes.
It is not reusable to make everything depends on Unity. Better to use 2D Arrays and draw block according to array data.
Here sources of such tetris game:
Just create a model for each shape piece, then add a mesh collider.
As the pieces fall and connect with another piece, set them to isKinematic = false so they stop moving.
I am looking around for ideas relating to a tetris game, too. Probably more like the Japanese game, puyo puyo, but the details I would think are similar.
I wouldn’t use the in game physics by making the blocks rigid bodies. Rather, you could create a 2d array to store all of the positions of the fallen blocks/pieces/gooballs. You could restrict the falling pieces to the grid as well, or let them move more freely and use the colliders to determine when the falling piece has landed. When a falling piece collides with a landed piece, then you could start a timer only allowing the piece to rotate or move down. Then you can store that piece in your array and calculate whether to eliminate a row or a group of pieces or whatever. You would have complete control over how the pieces move, and I think it would make for MUCH smoother gameplay.
You could still use cubes to represent the pieces as a start, or use any other mesh and use a box collider around it. But if you use the built in physics than it might end up bouncy and harder to control, like this video I just found.
I think that prefabs would be great for things like the differently shaped pieces. Though it might not be so necessary for the interface.