rexrainbow / phaser3-rex-notes

Notes of phaser3 engine
MIT License
1.21k stars 261 forks source link

Moving Diagonally in Quad grid #196

Closed meetpatel1989 closed 3 years ago

meetpatel1989 commented 3 years ago

I have a couple of questions that I couldn't able to find from the documentation.

1) How can I move a chess object diagonally in the quad grid? I tried to set pathMode to 'diagonal' but still, the object moves to destination using vertical & horizontal path only. 2) Is it possible to get all the possible paths if I know the destination cell? 3) Can I move the chess to the destination by giving my own path?

For reference, please check the following image.

Screenshot 2021-08-13 114120

rexrainbow commented 3 years ago
  1. Set dir, to 8, to allow path finder checks Left-down/Down-right/Right-up/Up-left direction.
  2. Paths information are stored internally, but only build/return 1 path, according to pathMode.
  3. You can move chess to anywhere without running PathFinder before.
meetpatel1989 commented 3 years ago

@rexrainbow Thanks for the details it helped a lot! One last howTo question in the list. The plugin returns the shortest path from getPath but what if I want to move to destination from another path? For example, consider the orange arrow from the image I shared. Is there any option in which I can tell to find the path which includes a particular cell/node?

One more thing is, I checked the draw path demo. I noticed that path gets changed when I select the next block even if the cost of moving to a destination block is the same that is 4 blocks.

Screenshot 2021-08-15 234620

Please check the drawn path in the above image.

Screenshot 2021-08-15 234645

The new path should follow the 1st image path and should add the new block at the end but instead of that it creates a whole new path and changed the 3rd number block. I just wanted to know how the logic works here. Both paths have the same number of blocks to move then why does it gets changed? Is there a way I can stop this behavior?

rexrainbow commented 3 years ago

Is there any option in which I can tell to find the path which includes a particular cell/node?

No option for this use-case. You can divide path into multiple segments, find path along these segments.

The new path should follow the 1st image path and should add the new block at the end but instead of that it creates a whole new path and changed the 3rd number block. I just wanted to know how the logic works here. Both paths have the same number of blocks to move then why does it gets changed? Is there a way I can stop this behavior?

In this demo, pathMode is set to 'A*', which is a faster way to find a path, but the result path might not be shortest, because that A* mode did not search all possible paths. You might try to set pathMode to 'straight', to get shortest path. BTW, the result path is reversed from end tile to start tile.

meetpatel1989 commented 3 years ago

@rexrainbow Thanks for the help :). Can I use texture instead of shape for chess objects?

rexrainbow commented 3 years ago

Yes you can, use addChess to add any kind of chess game object.

board.addChess(chess, tileX, tileY, tileZ, align)

See this test

meetpatel1989 commented 3 years ago

Is there any option in which I can tell to find the path which includes a particular cell/node?

No option for this use-case. You can divide path into multiple segments, find path along these segments.

How should I divide the path into multiple segments? I couldn't able to figure it out.

rexrainbow commented 3 years ago

For example, from tileA to tileC, and tileB is the particular tile which has to include into path, then you can find path tileA -> tileB, and tileB -> tileC.

meetpatel1989 commented 3 years ago

Is it possible to find the path from A to B and B to C without moving the game object? Path finder's findPath or getPath takes only endtile as a parameter and assumes the game object is on the start tile. I want to know the path without moving the game object.

Thank you so much for your help. :)

rexrainbow commented 3 years ago

Try moveChess method, set chess to tileB, then find path from tileB to tileC. Finally, move chess to tileA back, using MoveTo behavior to move chess along path.

meetpatel1989 commented 3 years ago

Yes but for that, I have to move the chess to tileB. I want to show the new alternate path without moving the chess to tileB. The chess will move from A to B and B to C when the button is clicked.

Hope this will help to understand my point.

rexrainbow commented 3 years ago

PathFinder supports occupiedTest and blockerTest, which means that user has to put a chess at a (tileX, tileY, tileZ) first. To keep the character chess during path-finding stage, you might try to use another ghost chess only for path-finding. BTW, set parameter align to false in moveChess method, can move chess in board's logic position, without change position in game world.

meetpatel1989 commented 3 years ago

It worked! Thank you for the help.