qiao / PathFinding.js

A comprehensive path-finding library for grid based games
http://qiao.github.io/PathFinding.js/visual/
8.35k stars 1.31k forks source link

Avoid corner cutting #17

Closed tapio closed 11 years ago

tapio commented 11 years ago

Hello, I have a world which is based on a grid, but the characters roam freely in it. As such, I'd like to allow diagonal movement for the path finding, but not when it would cut over a corner. Below are pictures illustrating this:

Cutting corners: Cutting corners

Avoiding corner cutting: Avoiding corner cutting

My use case: a robot which is not infinitely thin cannot cut corners: Use case

Of course this should be optional. I think it could be added to the Grid fairly easily. Depending on how the pathfinding algorithms are implemented, perhaps in isWalkableAt or getNeightbours.

Here's a reference implementation of it for a different AStar pathfinder: link.

qiao commented 11 years ago

Thanks for the suggestion. I will implement it in the near future :)

rafaelcastrocouto commented 11 years ago

I dont know how much u wanna mess up with the code, but in src / core /grid.js theres a function called getNeighbors that handles the whole diagonal stuff. Maybe u should try adding some extra conditions there.

Em 06/11/2012 11:51, "Tapio Vierros" notifications@github.com escreveu:

Hello, I have a world which is based on a grid, but the characters roam freely in it. As such, I'd like to allow diagonal movement for the path finding, but not when it would cut over a corner. Below are pictures illustrating this:

Cutting corners:

Avoiding corner cutting:

Of course this should be optional. I think it could be added to the Grid fairly easily. Depending on how the pathfinding algorithms are implemented, perhaps in isWalkableAt or getNeightbours.

Here's a reference implementation of it for a different AStar pathfinder: link.

— Reply to this email directly or view it on GitHub.