PathFinding.js icon indicating copy to clipboard operation
PathFinding.js copied to clipboard

Path going straight through Towers (11111)

Open JanVeb opened this issue 3 years ago • 0 comments

Path going straight through TOWERS?

import { Grid, Finder, AStarFinder } from "pathfinding";

export let mapPath = [
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
];

let start_x = 0;
let start_y = 6;
let end_x = 12;
let end_y = 6;

export let waypointsDy = [];
export function getPath() {
  var grid = new Grid(mapPath);
  var finder = new JumpPointFinder({
    allowDiagonal: true,
    dontCrossCorners: true,
  });
  waypointsDy = [];
  let path = finder.findPath(start_x, start_y, end_x, end_y, grid);
  for (let i = 0; i < path.length; i++) {
    waypointsDy[i] = {
      x: path[i][1] * 64 + 32,
      y: path[i][0] * 64 + 32,
    };
  }
}

Capture

Tried to implemet pathfinder.js in Tower defense game, though cant figure out whats wrong, you can see code im using and screen shot of path returned by pathfinder, you can see it goes straight through the towers??? Whats wrong? 1 is blocked, 0 is open, right?

JanVeb avatar Dec 11 '22 11:12 JanVeb