x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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..

alt text

Product Version: UE 4.19
Tags:
more ▼

asked May 30 '18 at 10:50 PM in Blueprint Scripting

avatar image

Carter10
19 3 7 14

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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

...

...

h*(w-1).............h*w

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:

https://answers.unrealengine.com/questions/180534/two-dimensional-array.html

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.

more ▼

answered May 31 '18 at 12:27 AM

avatar image

FlameOfIgnis
397 5 5 13

avatar image Carter10 Jun 02 '18 at 01:54 AM

Thank you for your response, appriciated , I understand your idea ,but not much how to apply it to the situation , let's say i have a real life-like chess board , to represent it in UE4 :

1- along the Y axis will be Columns labeled by the letters a,b,c,d,e,f,g,h .

2- along the X axis will have Rows labeled by the numbers 1,2,3,4,5,6,7,8

Isn't that similar to data table in ue4 ..,,???

just tell me if it's right or it's a disaster , so My plan is :

1- To create the struct called Columns concists of individual variables of type String or Name called a,b,c,d,e,f,g,h ( they are saying that names are faster to process i don't know)

2- To create a Data-table called "CrossSection" consisting of the struct called "Columns"

3- and the columns of the Data-table will be automatically the key names of the individual variables type String or Name ( a,b,c..,h) created inside the struct "Culumns"

4- then create rows named 1,2,3....8 which are the rows of the data table and set the variables values in the cross sections of the table to be respectively a1,b2,c3.........f8,g7,h8 = those are variables type Name or String which i set in the rows (1,2,3...8) of the Data-table ...

5- pull these values when needed in the graph with the nodeS Data-table or create an array from them if i wish to represent each tile of the whole board .

alt text

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question