-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add allowCrossDiagnal
option
#63
base: master
Are you sure you want to change the base?
Conversation
@yyx990803 Hmm... I had the same feature in my own pathfinding library, but I was considering ditching it, because it didn't sound much useful to me. Can you mention some games/demos where agents can make such moves through walls ? |
Pixel Dungeon is one the best roguelikes on Android and it allows this behavior. The image is probably a bit misleading, since this is more about being able to "squeeze" through enemies rather than through walls. |
This PR introduces another flag which adds more complexity. I'm not sure how useful is this feature of allowing squeezing through obstacles? More votes are needed before this can be accepted. |
My original image was probably misleading, I've updated it to use hostile creatures as the example - in most roguelikes, the player expects to be able to move like that. |
I stumbled upon this PR while trying to solve a similar issue in my own application. While it seems useful at first glance, I tend to agree with @imor and @Yonaba that it adds unnecessary complexity and is not necessary functionality for the core pathfinding library. It's also somewhat unintuitive to think of it being used with It seems like a very context specific issue that should be handled by the application on a level above the pathfinding library. For example, in my game, I've only had to deal with this issue when the player attempts to move short distances when surrounded by different configurations of enemies. (For longer distance movements, the issue becomes less apparent, and it is perfectly natural for the player to pathfind around the enemies). I handle it with specialized player action code, and avoid invoking the pathfinder completely. |
@doggan while I don't really care if this PR gets merged or not, I'd argue otherwise:
In short, I don't think it's fair to label the PR as adding "unnecessary complexity". |
IMO, the best way to handle it is to introduce a new flag called We can have 3 enumerations to represent the strategies,
|
@qiao +1 for enum, although this would make it a breaking change? |
@yyx990803 Yes it will be. And I think the current API is messy and needs to be redesigned. Such as
var path = PF.findPath({
strategy: PF.Strategies.AStar,
start: [0, 0],
end: [4, 5],
matrix: [
[0, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
....
],
heuristic: PF.Heuristic.Manhattan,
allowDiagonal: true,
cornerCuttingStrategy: ...
})
|
+1 for the new API. Also would be nice to have the default strategy/heuristic (probably AStar + Manhattan) |
Enum solution and new API look good. @yyx990803 Sorry if my original post came off as too harsh - I did not mean to label your PR as being unnecessary 😔. I only intended to say that 1). the proposed flag felt unintuitive when used in combination with other flags (which is addressed by the above enum solution), and 2). depending on the game, this problem may be addressable in the game-specific action code. |
Just to refine this I propose following changes. A) No obstacles in diagonal boxes
B) One obstacle in one of the diagonal boxes
C) Two obstacles in the diagonal boxes
Of all the possible combinations of allowing or disallowing A, B or C the above listed cases were the only sensible choices. Forbidden cases are listed below -
@qiao Instead of making it a breaking change right now can't we just accept a new option which, if present, overrides the behaviour of allowDiagonal and dontCrossCorners options and mark these older options as deprecated at the same time?
This will allow for a gentler upgrade for users. |
With e5b1678, 40d1579 and efb5c33 it is now possible to specify the diagonalMovement option to control the type of diagonal movement allowed. The possible values are Always, Never, IfAtMostOneObstacle and OnlyWhenNoObstacles. e.g. var finder = new PF.JumpPointFinder({
diagonalMovement: PF.DiagonalMovement.Always
}); These commits also add support for the diagonalMovement to the JumpPointFinder. The OrthogonalJumpPointFinder is no longer exposed directly but is used behind the scenes if the diagonalMovement is set to Never. The old options allowDiagonal and dontCrossCorners will work if specified but will be marked deprecated in the docs. diagonalMovement is the new unified option to specify diagonal movement. If both old and new options are specified the old ones will take preference. Docs and the demo are yet to be updated. A lot of new tests also need to be added. |
You can read more about diagonal movement in the use guide. Note that the user guide is still being actively written so please open a pull request if you find something wrong with it. |
This option allows movements like this:
Note this is the desired behavior when it's hostile creatures instead of walls. When this option is used, usually wall corners are always connected.
This PR only changed the AStar finder - if you think this is a good idea, I can modify other finders and their respective comments/documentations as well.