easystarjs
easystarjs copied to clipboard
Transitional tiles
I'm looking for a way to make transitional or "bridge" tiles, that could connect two other tile types.
I.e. Imagine that 0 is terrain, 1 is stairs and 2 is a wall.
let grid = [
0, 0, 0, 0, 0, 0,
0, 2, 2, 0, 2, 0,
0, 2, 0, 0, 2, 0,
0, 2, 0, 1, 2, 0,
0, 2, 2, 2, 2, 0,
0, 0, 0, 0, 0, 0
]
All tiles (0, 1, 2) should be acceptable, but in order to get from 0 to 2 or vice versa, 1 must be crossed.
I can't find a built-in feature to support this and the directional conditions are not exactly what I'm looking for.
Any suggestions?
You first run an algorithm to make some 2's become 0 whenever there is a bridge at top or bottom:
0
1
2
or
2
1
0
Then just run the pathfinding algorithm normally to get the path.
You can do this by using the setDirectionalCondition()
function. You need to write code to loop over your entire grid and decide which direction tiles can be entered from. Based on your example, [1][1] can only be entered from the right and the bottom. While [3][3] can be entered from all directions. I am doing this exact thing in my code, however I have 10 levels, not just 3. I may be able to post some code if you wish.
Here's an example, the top is my grid, the bottom is my path, where step 0 is A, and step 1 is B etc. The path is only allowed a difference of 1, and no diagonals are allowed: