getting tiles relative to in a Grid of tiles
Hi, thank you for your support.
i'm facing a situation in blueprint where i have a grid of tiles and i created an array of tiles indexed with integers from 0 to 120 so i have 120 tile ,
Now what i want is to make the tiles (that are allowed for my static actor to move to ) glow , so how can i start thinking about the logic to get the indexes of the tiles that sits straightforward relative to a certain tile index ??, or in any direction i want ,basically what i'm talking about is like a chess board and setting the allowed moves for a certain piece like Knight .
what i want resembles exactly the default chess game in win 7 where they are setting the tiles allowed to glow picture below..
asked May 30 '18 at 10:50 PM in Blueprint Scripting
So, if your board is h*w, and you are indexing them as
1 2 3 4 5 ....w
w+1 w+2 w+3....2w
To find the grid one above, you add -w to the index.
To find the grid one below, add w.
To find the left/right, add -1/1.
To check if you are in the left or right edges of your grid, check if your index%w == 1 or w-1.
To check if you are in the top or bottom edges, check if your index is less than w (top edge) or more than h*(w-1) (bottom edge).
Its a lot simpler in C++ with 2d arrays, if you know how to use C++ i recommend you use it instead. If the math above is too much work for you, or your game has a lot of complex rules, you can check out this solution instead:
You basically create a struct called row, that has an array with the size of your w, and your board is an array of rows.
answered May 31 '18 at 12:27 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here