Monday, May 17, 2010

Houdini Tetris


SOP Level

I started with a 4x2 grid, and deleting primitives to create the tetrominos in the game. Each tetromino consists of 4 primitives.



All of these geometries went to a Switch SOP. The input parameter has an expression that randomizes the input by time. The flat shapes are later extruded. This will be the source of the RBD objects in the DOP level.



DOP Level

RBD Object DOP

When bringing them into DOPs, a tetris piece needs to be "emitted" not only on the first frame, but also when the piece before it hits the ground. This is done by the expression in the Creation Frame parameter:

if($FF==1 || dophasfield("..",$OS+$SNOBJ-1,Impacts,Impacts,0,flags)==1,$F,0)

In DOPs, when an RBD object makes contact with a collision surface, there will exist Impact data called "flags". So once the current object, $SNOBJ-1, receives this flag, a new piece will be created.

Group DOP

I created two groups, one called "falling" which is the current piece, and "hit" which are the pieces at rest. The groups are detected by the Y velocity.

RBD State DOP

An RBD State DOP was used to force the velocity data to zero of the "hit" group. This will keep the pieces from bouncing and moving dynamically.

Motion DOP

In a Motion DOP, position was overridden using CHOPs. I could control the position of the falling piece using the keyboard or a game controller via CHOPs while the simulation was running.



CHOP Network

The CHOP Network records a graph while DOPs is running and can directly move the pieces in realtime. The result of the network above plugs directly into the Z position of the Motion DOP.

Resulting curve for side to side motion.

DOP Network


Afterthoughts

This was an experimental project and I learned alot about DOPs and CHOPs. I may later come back to this one to try and figure out how I can rotate the pieces without any bugs and of course enable the blocks to disappear after creating a line.