A bot used for https://code-your-snake.codingmaster398.repl.co/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
3 years ago
|
# Diagonal Movement
|
||
|
To disable diagonal movement you need to configure the finder. The finder takes
|
||
|
a configuration object with an option called `diagonalMovement`. Setting this
|
||
|
option to `DiagonalMovement.Never` will disable diagonal movement completely.
|
||
|
Let us try it.
|
||
|
|
||
|
```javascript
|
||
|
var finder = new PF.AStarFinder({
|
||
|
diagonalMovement: PF.DiagonalMovement.Never
|
||
|
});
|
||
|
```
|
||
|
|
||
|
See that the path is straight now:
|
||
|
|
||
|

|
||
|
|
||
|
The `diagonalMovement` option can take any of the following values:
|
||
|
|
||
|
* Always
|
||
|
* Never
|
||
|
* IfAtMostOneObstacle
|
||
|
* OnlyWhenNoObstacles
|
||
|
|
||
|
To understand them consider the following four simple maps labelled A, B, C and
|
||
|
D. A has no obstacles for diagonal movement from green to orange cell, B and C
|
||
|
have one obstacle and D has two obstacles.
|
||
|
|
||
|

|
||
|
|
||
|
## Always
|
||
|
With this option PathFinding.js will always find a diagonal path, irrespective
|
||
|
of the obstacles when moving diagonally.
|
||
|
|
||
|

|
||
|
|
||
|
## Never
|
||
|
With this option PathFinding.js will only find straight paths and will never
|
||
|
find any diagonal paths.
|
||
|
|
||
|

|
||
|
|
||
|
## IfAtMostOneObstacle
|
||
|
With this option PathFinding.js will find diagonal paths only if there is at
|
||
|
most one obstacle for the diagonal path.
|
||
|
|
||
|

|
||
|
|
||
|
## OnlyWhenNoObstacles
|
||
|
With this option PathFinding.js will find diagonal paths only if there are no
|
||
|
obstacles for the diagonal path.
|
||
|
|
||
|

|