Before updating to Windows 10 you may need to return your Pro license. More information here

Tetris Unity game structure C#

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.

more ▼

asked Mar 22, 2012 at 07:07 PM

avatar image

1 18 12 14

(comments are locked)
10|3000 characters needed characters left

2 answers: sort oldest

Simple. 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.

more ▼

answered Mar 22, 2012 at 07:35 PM

avatar image

6.9k 56 63 92

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered May 31, 2012 at 12:29 AM

avatar image

31 1 2 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Mar 22, 2012 at 07:07 PM

Seen: 3267 times

Last Updated: May 31, 2012 at 12:32 AM