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.
 

1.7 KiB

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.

var finder = new PF.AStarFinder({
    diagonalMovement: PF.DiagonalMovement.Never
});

See that the path is straight now:

Screenshot

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.

Screenshot

Always

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

Screenshot

Never

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

Screenshot

IfAtMostOneObstacle

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

Screenshot

OnlyWhenNoObstacles

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

Screenshot