1
\$\begingroup\$

Given this map:

enter image description here

The floor tiles are separated from the rest (it's a map made in Tiled in separate layers) and as you can see, the id numbers are not in sequence.

How I would go about making connections from node to node so later the pathfinder can find a path?

The best approach I can think of is to iterate over all tiles (not just the floor ones) and that way the id's can be in sequence, but I want to find a way around this method because there's has to a way that I can't think of right now.

\$\endgroup\$
1
\$\begingroup\$

Instead of having Id numbers you can assign a cost value to each tile based on the state of the tile. For example : if tile has enemy then give it cost value of 10000 and if there's a loot box then give it cost value of like 1. Your pathfinding algorithm can interpret this cost value as cost of connection and use this cost value to find the most favourable path for you.

consider this 1d array representation of 4x4 map, where tiles with 5 cost value has enemy and tile with 1 cost value has loot boxes, and 8 cost value for collider.

1,1,1,8,
1,5,1,8,
1,8,1,8,
5,5,1,1

the most favourable path here is (array indices) : 0-1-2-6-10-14-15

\$\endgroup\$
0
\$\begingroup\$

You could use dijkstra's algorithm where each node is on a floor tile

Youtube tutorial

You could generate the nodes & build connections once on initialisation. Traverse the map and place nodes on floor tiles. Look around the tile for other floor tiles and make new node connections.

\$\endgroup\$
  • \$\begingroup\$ Thanks. I know how to connect each node in a sequence number, because if you have the same number of tiles en each row, you can do simple math, but in this case the floor tiles numbers are detached from the other tiles and in some rows you have 16 tiles, in others you have 4, there's no consistency. Maybe i just consider all tiles the same and do it the usual way. \$\endgroup\$ – Jh62 Oct 28 '16 at 11:30
  • \$\begingroup\$ Are you saying that the tiles on a separate layer means that you can't know where the walls are as the wall information is on a different layer also? I guess I dont understand the problem. \$\endgroup\$ – RobM Oct 28 '16 at 13:15
  • \$\begingroup\$ Yes. That's it. The simple solution would be to put all the tiles (walls and floor) in the same layer and add a property through tiled and differentiate them at runtime. That way the sequence number would be in order and then i can just separate the tiles in code into different arrays. I just really wanted to use separate layers in Tiled, but I think it's not worth it. \$\endgroup\$ – Jh62 Oct 29 '16 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.