Skip to content

Path going straight through Towers (11111) #207

Open
@JanVeb

Description

@JanVeb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions