Have you ever seen those animations
of a soft-body Tetris game? There’s this channel C4D4U that has
been uploading different versions of the same concept for more than 3 years now. But apparently that’s not an
actual game, so I always wondered: would that be fun to play? Let's find out. I started the journey by doing some research
on how to work with soft-body physics in Unity. I found a couple of frameworks that do the
trick and I ended up using one called Obi. Most of these plugins follow a similar
approach: they transform "rigid" 3D models into a collection of tiny spheres, or
"particles", so that we can apply forces to different points of the object independently
instead of dealing with it as an atomic piece. These particles follow several constraints to more
or less keep the aspect of the original model, but allowing small alterations to convey
the impression of the object being soft, wobbly or squishy. I had to test the tools before
working on the Tetris clone, and I have to say I had a
ton of fun doing it, like... look at this guy. I might have spent more time than planned
playing around with these silly objects, but eventually made a couple of scenes
to try controlling soft-body objects and making them collide with each
other to see how they behave. Once I felt comfortable with the framework I was
ready to build some jelly-looking Tetris pieces. So I modeled 3D versions of
the original Tetris blocks. By the way, these are called "Tetrominoes",
and are all the geometric shapes we can build out of four squares connected at the
edges, apart from rotations of these. In my models I decided not to make
these inner cubes visible though. I imported the models into Unity and assigned them
materials following the Tetris color convention. Finally, I let the framework
do its magic and turned them into something I would definitely chew. There are many settings we can tune to achieve
different levels of chewability by the way. This is good enough for now. At this point we have a simulation similar to
the one that inspired me to work on this project, it’s time to turn it into a game. I started by making different tetrominoes
randomly spawn from the top of the screen and I gave the player control over the
position and rotation of the falling piece. It is Important to note here that the
player controls are based on physics, I decided to move and rotate the
pieces by applying forces to them. We need to do it like this to make them feel
wobbly, there would be no feeling of softness if the environment wasn’t
ruled by the laws of physics. This is a big change for the user experience
compared to more standard Tetris games, and something we have to accept
if we want soft-body dynamics. At this point we can stack soft tetrominoes on top
of each other, but eventually we ran out of space, so we need to develop the
classic line clear mechanic. This one is really tricky in our case. There’s two things we need to deal with: first
of all we need to identify when to clear a line, which is not trivial because our game space
is continuous, is not a discrete matrix as it is in the original game, but let’s assume
that’s already taken care of for a minute, then when a line is cleared we usually need
to break the tetrominoes into smaller pieces, to remove the parts of each block
that were in the cleared line. I focused on this second problem first. In classic Tetris this is relatively easy to do, because the pieces are built as groups of small
squares (which, by the way, are called "Minos"), but our 3D physics-based non-discrete context
makes this more complex: pieces can be in weird angles and their decomposition
is also technically more challenging. I considered three different approaches
to tackle breaking the blocks apart. At first I was thinking of doing
something similar to the classic game, building the tetrominoes as a set of four
minos tied together in a more literal fashion, so that I could make some of them
disappear when a line is cleared. In this case the minos would be 3D cube models. The thing is I wasn’t sure how that would go
along with the idea of having soft-body pieces, would each cube be a soft-body? How were they
going to stick together to form a tetromino? And were they going to feel
soft in this configuration? There were just too many open
questions with this approach. I also tried cutting the tetromino along
a plane, defined by the cleared line. And I mean cutting the 3D mesh of these
gummy-bears like we would do with a knife. The problem with this approach is
that it strays too far from Tetris, it would allow us to have many different
shapes in play, and thus making it extremely difficult to fit new pieces into the empty
spaces, which is the fun part of this game. So I decided to stay true to the classic
approach, as true as I could at least. Tetrominoes break apart as if they
were built as a set of four cubes (when they are not really) and
clearing a line takes away some cubes. Technically speaking, I did it by
replacing the 3D models with new ones which are conceptually missing minos,
this switcheroo magic-trick happens in an instant so the player perceives it
like the pieces adapt into new shapes. As a first step I made them decompose into
their minos, and then I improved on that to replace them with the actual shape
that results after the line is cleared. As a final note on this, notice that these approaches introduce
more differences with the original game. For example, a tetromino could be placed in a particular position that
allows new decompositions. See this cube, we can now make it land
at a 45 degree angle and then, maybe, the line clear just considers the mino on the
bottom, turning this piece into a tiny L-shape. This doesn’t happen in Tetris. But this kind of depends on how we identify when a line needs to be cleared,
let’s go back to that one now. I developed an algorithm which defines what
it means to complete a line in this game, which also supports adding a bit of
tolerance, meaning to accept having tiny gaps between pieces in a horizontal
line, to make it easier and more fun to play. It works by constantly casting an array of
rays, for each line, looking for pieces. If all of the rays watching at
a particular line find a hit, that means the line is
complete and should be cleared. Tolerance is introduced by allowing the
line clear even if not all of the rays find pieces in their way, as long as the amount
of successful rays passes a certain threshold. Before moving into the results, all this
talk about algorithms reminds me that… you really help me beat the YouTube
algorithm by leaving a like, please consider doing it if you enjoyed the
video so far, and also think about subscribing, I do silly games like this one all the time. With the core mechanics in place, it was time
to address some of the first experience issues. The most annoying thing at this point is that
the pieces tend to build unbalanced foundations, which makes it really hard to add more
pieces on top and continue clearing lines. This happens mainly because the
blocks react on impact and to gravity, causing them to rotate into awkward positions. I fixed the issue by making the
pieces lock into place after landing, completely disabling rotation
from that point forward. This improved playability, but I think it also made the pieces feel
less spongy, but I'm OK with the trade-off. I also tried limiting the falling
tetrominoes rotation to 90 degree angles, to make sure the pieces always
fall in Tetris-valid positions, but I didn’t like how the controls
felt, so I didn’t keep it. I then moved into developing the levels
system and the game over mechanic. The level increases after 10 lines are cleared
and this makes tetrominoes fall faster. The official Tetris guidelines (and yes,
that exists), defines a very specific curve for the speed of each level, which I
definitely didn't follow for this project. I also worked on a scoring system. The guidelines describe several
different approaches for this. I went for the most simple one, which assigns
different amounts of points to single line-clears, double clears, triples and quadruple line-clears,
which are called Tetris in case you didn’t know. All of these are also multiplied by the current level value to increase
points earned in harder levels. But there are some other scoring systems that
are far more complex than this one, these give points to the player when performing other types
of crazy maneuvers, not only for clearing lines. After that, I made it possible to see the
next tetrominoes the player is going to get, with a simple temporary UI for debugging purposes. The Tetris guidelines recommend
having the next 6 pieces in display, but showing 3 seems to be more standard. By the way, there’s a ton of crazy rules and
very specific details in these guidelines. I didn’t develop many of the supposedly
mandatory features of a game of Tetris. There’s lock delays, soft drops, ghost pieces,
hold options, T-spin recognition rules, and many other instructions
with catchy sci-fi names. Being too lazy to work on those, I decided to
call it here and went back to improving the player experience, mainly focusing on the issues
that arise from the twist we put on the game: the blocks being pieces of candy. The game is still a bit frustrating,
when the tower starts to rise high it becomes increasingly harder to
build on top of previous mistakes, so I made the play area much smaller
to keep the game short and sweet. Now we can place the camera closer, giving more attention to the true protagonists
of this Tetris variation: our slimey blocks. I actually did this because having too many
soft-bodies was causing performance issues. I also wanted to give the player some indication
of how full a line is, as it is not obvious just by looking at it, especially due to the tolerance
we added to the line completeness check algorithm. I added a little circular progress UI element to
the left of each line to help with this issue, and moved on to adding the finishing
touches to complete the game… I completed developing the display for the list of
next tetrominoes, made general improvements to the UI and tweaks to materials, put together something
for the background, played around with some post-processing for the camera, chose a font and
added some effects to make line clears more juicy… Then I turned my attention to sound and music,
this is how the game sounds at this point. Yeah… so I asked for help with the music and
the sound effects and this is the result. The music is adaptive by the way, it changes
slightly to match the tension of the game. Watch my video on adaptive music if you
want to learn more about this topic. I put together a very quick menu screen, simply a button to start the game
and a label showing your last score. I made some soft tetrominoes bounce around to introduce the core mechanic
even before the game starts. And that's it, the game is done. Well, it's not perfect, but it's good
enough to answer my original question: would a soft-body Tetris game be playable? What
do you think? Give it a try and let me know in the comments below. Personally, I think it
looks cool but it's actually a piece of -