0
\$\begingroup\$

SO I have a tile sprite like so : enter image description here

I want to use this to draw boxes on a 2d map using rule tiles. But I can't seem to get how to set rules for it in unity.

These are the rules I have :

enter image description here

And this is what I get when I try to draw a map:

enter image description here

I understand why I get this, as the rules 4 and 5 are redundant and rules 2 and 3 take precedence but I included them any to tell what I am aiming for.

I tried using custom rule tile, even there it seem like its more for connecting different tile rather then dealing with sprites of same tile

PS: also ignore the mirroring on rule 2, it has no purpose, just something I forgot take away when I took the screen shot

\$\endgroup\$
4
  • \$\begingroup\$ Pretty sure you can't do this. The tile rules system expects your walls to cover a full tile, not be the edge of the tiles. \$\endgroup\$ Apr 18, 2023 at 8:59
  • \$\begingroup\$ @JackAidley why would that matter to the adjacency rules? A thick wall in the middle of the tile (with a distinguished inside and outside face) follows the same tile adjacency rules as a thin wall on the edge. \$\endgroup\$
    – DMGregory
    Apr 18, 2023 at 10:50
  • \$\begingroup\$ @DMGregory: No, it doesn't. The adjacency of a wall at the top and bottom of that box are the same, in order to have them apply differently you need additional information to define an inside and an outside. \$\endgroup\$ Apr 18, 2023 at 13:40
  • \$\begingroup\$ That just means the adjacency information was entered incorrectly, as I explain in the answer below. It's not a fundamental restriction on where the pixels of the wall can be within the square area of the tile. \$\endgroup\$
    – DMGregory
    Apr 18, 2023 at 13:47

2 Answers 2

0
\$\begingroup\$

Switch tile 2 from mirroring (↔️) to fixed (⚪). The mirror rule is letting it sub-in for the job of tile 5, which you don't want.

For all the straight wall segments (tiles 2-5), add an arrow in the direction pointing away from the wall. e.g. for tile 2 that would look like:

  ⬆️
⬅️⚪✖️
  ⬇️

Think of these as the directions someone standing in the center of the tile could move without leaving the walled area. They can walk along the wall or away from the wall toward the interior, but not through the wall to the outside.

It's this extra "this way inside" information that lets the rule decide when to place a left wall or a right wall, a top wall or a bottom wall.

\$\endgroup\$
2
  • \$\begingroup\$ thanks for your answer, although this doesn't work ,as I don't have a wall on the straight edge tile , its just a straight edge which can be adjacent to something else , \$\endgroup\$
    – Snedden27
    Apr 18, 2023 at 14:55
  • \$\begingroup\$ Then you need to extend the rule tile to help it understand which "something elses" belong on the outside of the wall, and which "something elses" belong on the inside of the wall. You haven't shown enough detail in your question for us to speculate what rule would be appropriate for your use case here. \$\endgroup\$
    – DMGregory
    Apr 18, 2023 at 15:17
0
\$\begingroup\$

So I ended up creating two rule tiles ,

  1. For the top left border

enter image description here

  1. For the bottom right border

enter image description here

Then made sure I use those tile on the respective edges like so:

using UnityEngine.Tilemaps;

void Start() {
    tm = GetComponent<Tilemap>();
}

void placeBoxBorder( int width, int height, RuleTile bottomRightTile, RuleTile topLeftTile) {
        for (int row = 0; row < height; row++) {
            for (int col = 0; col < width; col++) {
                Vector3Int vector3Int = new Vector3Int(row, col, 0);
                // Draw top left edge
                if ((col == 0 || row == height - 1)) {
                    tm.SetTile(vector3Int, topLeftTile);
                }
    
                // Draw bottom right edge excluding the top right corner
                if ((row == 0 || (col == width - 1 && row != height - 1))) {
                    tm.SetTile(vector3Int, bottomRightTile);
                }
            }
        }
    }
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .