Add additional walkable tiles
Is it possible to make a tile in the matrix walkable (beside 0), without using setWalkableAt? I´m using the same matrix for pathfinding and building a tilemap and I need more than one field to be always walkable. If that´s not the case I would need two matrices for two basically identically parts of the map.
e: as i re-read the question, i think i did not understand what you are looking for.
hey @FelixB91, do you know about setting the grid from matrix?
var matrix = [
[0, 0, 0, 1, 0],
[1, 0, 0, 0, 1],
[0, 0, 1, 0, 0],
];
var grid = new PF.Grid(matrix);
Anything is possible!
On 27 Jan 2017 22:41, "FelixB91" [email protected] wrote:
Is it possible to make a tile in the matrix walkable (beside 0), without using setWalkableAt? I´m using the same matrix for pathfinding and building a tilemap and I need more than one field to be always walkable. If that´s not the case I would need two matrices for two basically identically parts of the map.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/qiao/PathFinding.js/issues/141, or mute the thread https://github.com/notifications/unsubscribe-auth/APoQYh8LiEnKaWPuYCVNZIMVTv3ocEAeks5rWnJ9gaJpZM4LwSuh .
@mfandl Thanks for your reply.
I did set the grid form a matrix, but I did something like this:
var matrix = [ [0, 0, 0, 1, 0], [1, 2, 2, 2, 1], [0, 0, 1, 0, 0], ]; var grid = new PF.Grid(matrix);
Since I use this matrix also for my tile map, I replace each number with a tile. Let´s say 0 is grass (walkable), 1 is a wall (not-walkable) and 2 is a brick-road (walkable). I want to "teach" the pathfinding algorithm that he can also walk over 2 and not only over 0. Right now he treats every number beside 0 like it´s not-walkable.
If that´s not possible, I would need two separate matrices wich would be ofc possible as well, but also more manual work (since I'm not using an editor to generate the map yet).
Edit: Apparently I don't know how to format the code properly. Sorry!
@FelixB91 Ah so. Sorry I didn't get it before. if you are OK with editing the library, you can update the condition on line 71 in core/Grid.js to match your criteria.
I just scanned through source code to see where the walkable field node is set and did not try it, but I think this should work.
Thanks a lot @mfandl! This looks pretty good, I´ll try it out later! 👍
This is just a personal choice but, what's wrong with having 2 matrices? Isn't it clearer and more easily testable? Separation of concerns and all that. If you have a constructor that takes some constants for rows and columns and returns a matrix then you'd be sure to always have the same structure each time.
@rohan-deshpande that´s probably true. Honestly I didn't really think this through yet. My current "project" is actually more of a feasibility analysis, regarding pathfinding in general. But I guess you're right, that would probably be cleaner from the coding perspective and less susceptible to errors. I'll give it a try!