- Home /
Area sensing - Needs fixing
I am working on a game called Cubit, a 3d morph of Tetris. How it works, basically, is that you have to fill up a layer on the outside of a cube (which you can rotate, similar to rotating blocks in normal Tetris). You can only work on the layer you are on, and not outside of it. Cubes too far off to the right, top, left or bottom would "pop".
I am trying to make it so that when a cube tries to become solid outside of the level's bounds, it pops, like I described -
if (Input.GetKeyDown(KeyCode.L)){
if (transform.position.x + cubeCursor.transform.position.x > (-1 - Tetris.lvl) &&
transform.position.x + cubeCursor.transform.position.x < (1 + Tetris.lvl) &&
transform.position.y + cubeCursor.transform.position.y > (-1 - Tetris.lvl) &&
transform.position.y + cubeCursor.transform.position.y < (1 + Tetris.lvl) &&
transform.position.z + cubeCursor.transform.position.z < (-1 - Tetris.lvl) &&
transform.position.z + cubeCursor.transform.position.z < (1 + Tetris.lvl)) {
Materialize();
} else {
Destroy(gameObject);
}
}
The cubes you are placing are parented to the cursor, which shifts left-right and up-down. I figured this would work just fine, but the area they are solidifying in is not where I told it to be.
They should be able to materialize in the 4x4x4 region outside the central cube. However, they are limited to a much smaller region. The Tetris.lvl variable affects the size of this region, and thus the level that is being worked on. Anyone got ideas on what's going wrong?
Answer by OBV10U3_NINJA · Sep 06, 2015 at 07:20 PM
I fixed it myself. The process itself is highly complex, and I am unable to put the entire thing here, but to be basic, instead of spawning the cubes at a position from the cursor, I made a script for them to move after they are created. It involves a lot of switch statements and methods.
However, I will show you a bit of it - I came up with an ingenious way of having the blocks figure out where they are supposed to go. In a script, I made a globally accessible integer, called "HoloCounter", which counts the hologram-cubes. In the start function of each cube, I have it so they increase it by one, taking advantage of the fact that the computer runs the whole way through the functions of one object before going through the functions of the next. Then I made a bunch of methods, "TetraPattern1" through "..7" (which are based off of the chosen cube pattern), and in each, did variations of this -
void TetraPattern1 () {
switch (CubePlacer.HoloCounter){
case 1:
break;
case 2:
transform.Translate(0f,1f,0f);
locX = 0;
locY = 1;
break;
case 3:
transform.Translate(1f,0f,0f);
locX = 1;
locY = 0;
break;
case 4:
transform.Translate(1f,1f,0f);
locX = 1;
locY = 1;
break;
default:
print ("Too many holocubes or HoloCounter not working properly");
Destroy(gameObject);
break;
}
}
Impressed?
EDIT - The purpose of the difference here, is the locX and locY integers are used in place of the transform.position.x and y positions. I also removed the transform.location.z ones. I don't know why it worked, but it did.
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.L)){
if ((locX + CubePlacer.cubeCursorX > (1 - Tetris.lvl)) &&
(locX + CubePlacer.cubeCursorX < (4 + Tetris.lvl)) &&
(locY + CubePlacer.cubeCursorY > (1 - Tetris.lvl)) &&
(locY + CubePlacer.cubeCursorY < (4 + Tetris.lvl))){
$$anonymous$$aterialize();
} else {
Destroy(gameObject);
}
}
Your answer
Follow this Question
Related Questions
Least heavy processing detection method 1 Answer
OnTriggerEnter2D not Working 0 Answers
Full Performance On Melee Combat 0 Answers
Trigger Detecting Player Even When Not Inside 1 Answer
Detecting contact on colliders? 0 Answers