like, sliding tiles around in increments.

So. It is like moving a sliding puzzle game where the objective is to make the image. The thing is… There will be more than one space open. So. If there is a space open the piece can slide into that open space… If there are several pieces in a row. They can all be pushed in the direction of that open space in one motion.

At the moment… I’m thinking a for loop with raycasts perhaps. Such that it checks to see if there is an open space next to it. If there is. It will be moved. But if that empty space has a tile on it… It will ask that tile piece if there is an empty space next to it in the same direction. That seems very wasteful.

What is the best way to do this?

Forget the Unity way of “doing it” and implement the game model in a traditional manner. Unity is the display engine and should not be the factor that determines how a problem is solved.

This quick demo illustrates a game play model that has nothing to do with Unity.

http://dl.dropbox.com/u/4910637/Zombies/WebPlayer.html

The model of the game board is stored as an array, I don’t use raycasting to determine if a zombie has fallen in a swamp, the game mechanics inherently know that a zombie has fallen in. The graphic fidelity is irrelevant, whether it be ASCII text, Unity, CryEngine, or laser beams.

See here for a project that uses an array for the gameplay. A sliding puzzle game would be simpler than that, but it should illustrate the concept.

–Eric

Interesting tetris clone.

I have a question about the manager script.

About how it stores the location of the blocks in the field. I’m a little confused on how it works. specially the bold area. How do you make sure it doesn’t overwrite block information that is already stored?

// Make on-screen cubes from position in array when the block is stopped from falling any more
// Just using DetachChildren isn't feasible because the child cubes can be in different orientations,
// which can mess up their position on the Y axis, which we need to be consistent in CollapseRow
// Also write the block matrix into the corresponding location in the playing field
function SetBlock (blockMatrix : boolean[,], xPos : int, yPos : int) {
	var size = blockMatrix.GetLength(0);
	for (y = 0; y < size; y++) {
		for (x = 0; x < size; x++) {	
[B]			if (blockMatrix[x, y]) {
				Instantiate (cube, Vector3(xPos+x, yPos-y, 0.0), Quaternion.identity);
				field[xPos+x, yPos-y] = true;[/B]
			}
		}
	}
	yield CheckRows (yPos - size, size);
	SpawnBlock();
}

Oh… I think I’m starting to get it now.

I’ve never used a boolean array. So the way it is storing stuff in the field for the blocks… For a particular x and y position get marked as true if a block is there.

Well. I played with this a bunch… Can’t get it to work. and I’m not sure this is good way to solve the problem. Also tried doing this with rigidbody physics. I can’t get this stuff to behave in a predictable way. It is like a sliding puzzle but a sliding puzzle with more than one hole in it.

What have at the moment has several problems. I would still need to find a way to detect the direction the object is being pushed… but the biggest problem it has. a stack of pushed tiles doesn’t know there is an empty space between it… So it just pushes the whole stack of blocks. I don’t know a way to organize an array to deal with that.

var myValue:int;



var mySpecial:int;



var field : boolean[,];



var myArray = new Array();

var myCounter:int;

var myEndValue:int;

var hit:RaycastHit;

var firstBool:boolean;

var secondBool:boolean;



function Start()



{

var objects = GameObject.FindGameObjectsWithTag("p_box");

field = new boolean[20, 20];

for (var  obj : GameObject in objects) {

    if (obj.tag.Contains("p_box")) {

field[obj.gameObject.transform.position.x,obj.gameObject.transform.position.z] = true;

}

}

}



function Update () {





Debug.DrawLine (transform.position, Vector3 (0, 0, 100), Color.red);







if(Input.GetKey("r"))



{





if (Physics.Raycast (transform.position, Vector3 (0, 0, 100), hit))

{

myArray.Clear();

//normal reverse it.

		if(field[hit.transform.position.x,hit.transform.position.z+1.0] == false)

		{

		field[hit.transform.position.x,hit.transform.position.z] = false;

		firstBool=true;

		}

						else

						{

						var objects = GameObject.FindGameObjectsWithTag("p_box");

						for (var  obj : GameObject in objects) {

				    		if (obj.tag.Contains("p_box")) {

								if(obj.gameObject.transform.position.x == hit.transform.position.x  obj.gameObject.transform.position.z > hit.transform.position.z)

								{

									myArray.Push(obj);

								}

									secondBool=true;

								}

								}

								}

				

}





}

 





if(firstBool)



{

if(myCounter<9)

{

hit.transform.position.z += .1;

myCounter++;

}

else

{

hit.transform.position.z += .1;

testA = (Mathf.Round(hit.transform.position.z));

hit.transform.position.z = testA;

myCounter -= myCounter;

field[hit.transform.position.x,hit.transform.position.z] = true;

firstBool = false;

}

}





if(secondBool)



{

var objectstwo = GameObject.FindGameObjectsWithTag("p_box");

for (var  obj : GameObject in objectstwo) {

		    if (obj.tag.Contains("p_box")) {

		if(obj.gameObject.transform.position.x == hit.transform.position.x  obj.gameObject.transform.position.z > hit.transform.position.z)

			{

			myEndValue = myArray.length*10;

			if(myCounter<myEndValue)

			{

			//need to add something here to deal with the array issue.

			field[obj.gameObject.transform.position.x,obj.gameObject.transform.position.z] = false;

			myCounter += 1;

			obj.gameObject.transform.position.z += .1;

			field[obj.gameObject.transform.position.x,obj.gameObject.transform.position.z] = true;

			

			}

			else

			{

			myCounter-=myCounter;

			secondBool =false;

			//need to round the values for on the second

			}









}

}

}

}

}

Dear friends,
I have been trying since quite some time on this slider puzzle. I have made 4X4 cubes block with the following script .
I have declared variables as TileWinPos, TileCurPos and GetTilePos…
TileWinPos - declares and initializes the winning position
GetTilePos- to find the gameobject by name
TileCurPos - to store the current position of the Tile

Now i am trying to check if TileCurPos matches with the TileWinPos ,if it is true then load a level.
I tried checking each variable values through debug log,everything seems to be correct, but i am not able to load the level.
The Script is as below…
can anyone tell me why i am not able to load the level here ?

To test this you can follow this tutorial ----> http://www.youtube.com/watch?v=sSteq3uzICI
and append the following code.

Note: I am checking only for 7 tiles(cubes) which are shuffled…rest eight tiles are not shuffled.

Thanks in advance

var emptyslot : Transform;
var xtemp;
var ytemp;
var slide:AudioClip;

private var GetTile1Pos : GameObject;
private var GetTile2Pos : GameObject;
private var GetTile3Pos : GameObject;
private var GetTile4Pos : GameObject;
private var GetTile5Pos : GameObject;
private var GetTile6Pos : GameObject;
private var GetTile7Pos : GameObject;

var Tile1WinPos =Vector3(0.0,0.3,0.0);
var Tile2WinPos =Vector3(1.0,3.0,0.0);
var Tile3WinPos =Vector3(2.0,3.0,0.0);
var Tile4WinPos =Vector3(0.0,2.0,0.0);
var Tile5WinPos =Vector3(1.0,2.0,0.0);
var Tile6WinPos =Vector3(2.0,2.0,0.0);
var Tile7WinPos =Vector3(3.0,2.0,0.0);

function Start()
{

GetTile1Pos= GameObject.Find(“Tile1”);
GetTile2Pos = GameObject.Find(“Tile2”);
GetTile3Pos = GameObject.Find(“Tile3”);
GetTile4Pos = GameObject.Find(“Tile4”);
GetTile5Pos = GameObject.Find(“Tile5”);
GetTile6Pos = GameObject.Find(“Tile6”);
GetTile7Pos = GameObject.Find(“Tile7”);

}

function OnMouseUp()
{

if(Vector3.Distance(transform.position,emptyslot.p osition)==1)
{
xtemp = transform.position.x;
ytemp = transform.position.y;
transform.position.x=emptyslot.position.x;
transform.position.y=emptyslot.position.y;
emptyslot.position.x=xtemp;
emptyslot.position.y=ytemp;

}

}

function Update()
{
var Tile1CurPos = GetTile1Pos.GetComponent(Transform).transform.posi tion;
var Tile2CurPos = GetTile2Pos.GetComponent(Transform).transform.posi tion;
var Tile3CurPos = GetTile3Pos.GetComponent(Transform).transform.posi tion;
var Tile4CurPos = GetTile4Pos.GetComponent(Transform).transform.posi tion;
var Tile5CurPos = GetTile5Pos.GetComponent(Transform).transform.posi tion;
var Tile6CurPos = GetTile6Pos.GetComponent(Transform).transform.posi tion;
var Tile7CurPos = GetTile7Pos.GetComponent(Transform).transform.posi tion;

///////Debug Log//////////////////////
//Debug.Log(Tile1CurPos);
//Debug.Log(Tile2CurPos);
//Debug.Log(Tile3CurPos);
//Debug.Log(Tile4CurPos);
//Debug.Log(Tile5CurPos);
//Debug.Log(Tile6CurPos);
//Debug.Log(Tile7CurPos);

if(Tile1CurPos==Tile1WinPos Tile2CurPos==Tile2WinPos)
{
if(Tile3CurPos==Tile3WinPos Tile4CurPos==Tile4WinPos)
{
if(Tile5CurPos==Tile5WinPos Tile6CurPos==Tile6WinPos )
{
if( Tile7CurPos==Tile7WinPos)
{
Application.LoadLevel(12);
}
}
}

}
}