How to implement a connected border generator to a placement system

INFO:

Hello, I’m in need of figuring out a way to add connected borders to tilled dirt objects in my farming game. I’ve already made an entire placement system, but I’m stumped about how I could add a system like this. I’m NOT asking to be spoon fed, just an explanation or any ideas for how to complete this.

Once again, I’m not asking how to implement this feature just how I should go about doing it. ANYWAY, lets get into this post:

POST:

Essentially I have my placement system, and around all the edges of the farming tiles I need a border to cleanly wrap around all of the tiles.

This is what the tiles currently look like:

Now, to explain what I mean by having a connected border is like this:

I need all of the borders to seamlessly connect like above, I am REALLY not sure what to do about that. ONCE AGAIN, I already have a placement system that I scripted fully by myself - But I have no idea how to get the tiles to connect seamlessly like that.

One more thing is that I want to make sure that if a tile is rotated another direction, it won’t connect to the other ones.

1 Like

You can get the relative position of nearby land with CFrame:ToObjectSpace()
First check orientation
Then by using the relative position, find the touching ones and get rid of the border on both.

You could use a 2D array (array of arrays, actually, because lua doesn’t have 2D arrays). There seems to be visually only two possible orientations for your dirt object. For each square in the placement area, you could store an integer. 0 could mean that there’s no dirt object on the tile. 1 could mean that there’s a non-rotated dirt object, and 2 could mean that there’s a rotated one. You could also store the edge parts in some kind of array maybe, to be able to easily find and destroy them when necessary.

When a dirt block is added or removed, update the integer in the corresponding tile. After that, go through each of the four adjacent tiles. If an adjacent tile has a different integer and there’s not an edge between the tiles, create an edge between the tiles. If an adjacent tile has the same integer, and there’s currently an edge between them, remove the edge.