- Home /
Road/path creation on tile grid
Lets say I have a procedurally generated 32x32 tile grid in an isometric perspective for a sim-city type game that has different tile types, terrain, etc. Using C# Actions, I made it so when you click on a tile, you can toggle its selection with a nice little highlight graphic and everything. It's very nice, but I want to add more functionality to the tile selection so that the player can do a "line select". For instance, in a sim-city game, when you build a road, you can only select tiles in a straight line but can also turn in 90-degree angles that makes your pathway for said road. I am looking for advice on how to implement it. Does anyone have any suggestions how I could make that happen?
Answer by Acdia · Aug 16, 2020 at 07:29 AM
If you want to connect two points with one corner there are always two ways for It (for example from legt top to right bottom you can go past legt bottom or right top). I think it makes sense to simulate both and let the player decide which one to use. To geht the right tiles for the path it's helpful to have then in an 2d array. You geht the Start position when the player clicks. And constantly the end position as long as the player holds the mousebutton down and the tile howering on has changed. Now you need to know the positions of the tiles within the array. For example you can let the tiles save these on spawning. Next you have two loops. The first decreases or increases the x (in the array) of the start position until it has the same value as the x of the end position every loop you let the tile with the position in the array you can do some preview stuff. After x is finished you do the same thing with y so you geht every tile on the path. On release of the mousebutton you can let all tiles having a preview change to path tiles. If the player switches to the other option of the path, you just do y and then x.
Your answer
Follow this Question
Related Questions
How to create a rotating tiles with walls on edges of tiles? 0 Answers
How to texture huge tile grids? 1 Answer
Hexagon Match3 selecting adjacent objects and rotating clockwise, 0 Answers
can somebody help for the algorithm or code how implement this crossword math? 1 Answer
How to approach to a triangle snap grid 0 Answers