# How do you calculate walls between tiles in a 3d environment?

I have an int[9,8]tiles that stores numbers from 1 to 9 depending on a previous selection by the player. So for example:

``````// 1 = blue tile, 2 = yellow tile, 3 = red tile
tiles[0,0] = 1;
tiles[0,1] = 1;
tiles[0,2] = 1;
.
.
tiles[2,0] = 2;
tiles[2,1] = 2;
tiles[2,2] = 2;
.
.
tiles[5,0] = 3;
tiles[5,1] = 3;
tiles[5,1] = 3;

// Which looks something like this in the diagram below:
// 1 1 1 1 1 1 1 1 1
// 1 1 1 1 1 1 1 1 1
// 2 2 2 2 2 1 1 1 1
// 2 2 2 2 2 1 1 1 1
// 2 2 2 2 2 3 3 3 3
// 3 3 3 3 3 3 3 3 3
// 3 3 3 3 3 3 3 3 3
``````

The result is something like this:

The red lines marked on the image are the walls that will go inbetween each of the colour areas. I know how to loop through each tile and work out if the tile next to it in any of the four directions (North, South, East, West) is a different colour and hence a wall is required. I don’t know an efficient way to store the information and cancel out any walls that are found from looping through every tile.

Obviously the first time I scan a tile with the one below registering a different colour will indicate a wall. But then when I look at that 2nd tile in my loop, it will also register the need for a wall. So 2 walls will be created.

I would like to know if there is any easy way to calculate this wall information another way, but more importantly how can I store this information in say another int[,] array so I can generate the walls from there. Every tile in my game is a 1x1 quad rotated to point upwards. So the int array relates to the X and Z coordinates of the tile itself.

Any help would be greatly appreciated. It’s 6:12am and I have been up all night trying to figure this out for a game I am making.

You could just only check to places walls on the bottom or right as you scan your 2D array. That way you wont get duplicates.

Also always place walls on the top of row 0 or left of column 0.

One solution would be to store the wall information in a four-dimensional bool-array. Since a wall sits between two tiles, you need the coordinates of two neighboring tiles. The dimensions or the array would be:

0: tile A x-coordinate
1: tile A y-coordinate
2: tile B x-coordinate
3: tile B y-coordinate

The array would have lengths equal to the x and y lengths of your grid + 1 (for the non-existent tile at max + 1 coordinates, which doesn’t have to correspond to tiles for the process of checking for walls). For border cases, you would always set the bool to true instead of attempting to access the tiles array which would be out of bounds).

``````if(tiles[0,3] == blue && tiles[0,4] != blue) //pseudocode obviously
{
walls[0,3,0,4] = true;
}
``````

To create objects you simply place LEGO-style bricks in virtual space. Once you’ve built your model you can export to an STL file for printing on a Makerbot or similar printer. Aimed at the very young, Tiles offers a number of building styles including additive building by dropping blocks and “chip-way” that lets you remove material from a larger block. Unlike tools like Printcraft, which translate game worlds into STL files, this is a true CAD tool, albeit one with considerably reduced complexity.
https://forpc.onl https://jiofilocalhtml.run

,To create objects you simply place LEGO-style bricks in virtual space. Once you’ve built your model you can export to an STL file for printing on a Makerbot or similar printer. Aimed at the very young, Tiles offers a number of building styles including additive building by dropping blocks and “chip-way” that lets you remove material from a larger block. Unlike tools like Printcraft, which translate game worlds into STL files, this is a true CAD tool, albeit one with considerably reduced complexity.

You could just only check to places walls on the bottom or right as you scan your 2D array. That way you wont get duplicates. vidmate save insta

Thanks for sharing this information. Really great post.

In the tile-based approach, each visual element is broken down into smaller pieces, called tiles, of a standard size. These tiles will be arranged to form the game world according to pre-determined level data - usually a 2D array.
Tutuapp 9Apps Aptoide