# Making a Tetris. Help needed on; Making blocks stop at a certain coodinate so they dont go outside the camera view!

Hi people, hello again. I’ve been making my tetris but these are the two problems i really couldnt handle.

To explain the terrain:

I have a 80x160 board with a cube combinations that have 0.1 dept and 8 with and height per square. So this cube looks 2D from my camera and moves around freely. The rectangle board 80x160(Background) is about %30-35 of the screen and i will put score and stuff on right and left later.

1st Problem;
Ok so i want my cubes to stop at the edges of the background. What i mean by that, at tetris when you go with the cube to farthest left, it stops going left. At right it stops going right, but you can still move it to other directions. I want to do that with a command like, “Disable left movement when cube is on bla bla coordinates or something”. I can make a distance fucntion to stop movement, but " update() dist " is a very heavy function and i cant use that in every game i make. I want to learn the right way to do it with some kind of a coordinate variable.

2nd Problem;

a)How do i spawn new blocks with RNG.

b)How do i make sure i spawn one block when the other collides.(Probably with onCollisionEnter but still i wanted to ask)

As for the RNG and Spawning combination i have no idea whatsoever so i need help on that.
I havent tried collision problem yet but i want to confirm if its true before wasting some large time.

I want to make the blocks rigidBodies that are unable to rotate or move to any axis(I’ll move them with codes, i dont want any recoil when they collide). And when they collide with the terrain or any other block or Prefab replacement(There are four of them "L shape, T shape, I shape, CUBE shape blocks), they will be deleted and replaced with a Prefab(via Instantiate) that is also a rigidbody that is unable to move(or a kinematic body) with a diffrent texture and some light effects. And when this collides a new block will spawn. I’ll spawn the first block with function Start() and others with onCollisionEnter.

On some tetrises that are things like, “NEXT BLOCK INCOMING SIGN ON THE RIGHT, BONUS COMBOS FOR PONTS, A VISABLE PATH GOING DOWN SHOWING WHERE THE BLOCK WILL LAND”

Like this : http://www.ressim.net/i/4627443

I’d really want to have an idea how to make them. Dont give me entire codelines, i am making a tetris to learn. Give me the ideas and main script names, i’ll go on from there.

So are my ideas right, and how can i solve my questions. Any help is appriciated guys. PLEASE ANSWER IN JAVASCRIPT, i have “0” knowledge of C. Love you all…

An example of Tetris in Unity is here.