rexBoard pathFinder cost

Hi @rexrainbow,

How would you configure pathFinder to use the most “efficient” path when finding a path? Say I have a board of tiles. Some of them have a higher cost and should be slower to travel through them than others. How do I make pathFinder use the “fastest” route and not “shortest” route?

Currently have essentially:

this.pathFinder = scene.rexBoard.add.pathFinder(this, {
  occupiedTest: true,
  pathMode: 'A*',
  blockerTest: true,
  costCallback: (curTile, targetTile, pathFinder) => {
const speedCost = this.getTileAttribute(pathFinder.chessData.board.scene, targetTile, 'speedCost');
return speedCost;
  }
});

Thanks,
Dan

I think it should do that automatically, as long as you are providing the cost correctly. Have you logged speedCost?

Yes. Currently they are fractional… about .2 through 2.5. Do they need to be whole numbers? Do I need to weight it more than the default 10?

If you say that’s right, maybe I’ll just step through the code to see whats going on.

Thanks again,

Finally going to get this ting live in a couple weeks.

Hmm, I can’t get it to work like I would want. In this example, all the light green grass has a speed cost of 1. I set the speed cost of the swamp/trees to 10. In the example, the Lich is taking the shortest path with a total speed cost of 31. (3 times trees + 1 grass). The FASTEST path would be to go around the trees and go through 5 grass hexes for a total cost of 5.

I’m using this.pathFinder.findPath(targetTile) to get the path. I also tried this.pathFinder.findPath(targetTile, undefined, false);

Path finder finds ‘shortest’ path, i.e. path has minimal cost, returned from cost function.

In your case, cost function return speed value and you want to find path which has maximum total speed value.

Then you can design the cost function to return (MAXSPEED - speedValue) , higher speed value will return smaller cost value.