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.
Answer by Meltdown
Mar 22, 2012 at 07:35 PM
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.
Answer by ptpaterson
May 31, 2012 at 12:29 AM
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.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
5 People are following this question.
Classes, MonoBehaviours C#
Classes and Scripting
Flat Low Poly Terrain / Script a terrain
Multiple Cars not working
How do I stop Script from making multiple Cameras?