explaingit

qiao/pathfinding.js

8,688JavaScriptAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

JavaScript library with 11 pathfinding algorithms, including A*, Dijkstra, and Jump Point Search, for navigating characters around obstacles on 2D grid maps in games.

Mindmap

mindmap
  root((pathfinding.js))
    What it does
      Grid pathfinding
      Obstacle avoidance
      Path smoothing
    Algorithms
      A Star
      Dijkstra
      Jump Point Search
      Bidirectional variants
    Grid Options
      Diagonal movement
      Corner cutting control
      Distance heuristics
    Use Cases
      2D game navigation
      Simulation routing
      Algorithm comparison
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add A* pathfinding to a 2D tile-based browser game

USE CASE 2

Navigate a character around walls and obstacles on a grid map

USE CASE 3

Compare pathfinding algorithms side by side using the interactive visual demo

USE CASE 4

Smooth or compress a computed path to remove unnecessary zigzag steps before animating

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice (MIT License).

In plain English

PathFinding.js is a JavaScript library for finding paths on grid-based maps. If you are building a 2D game or simulation where a character or object needs to navigate from one point to another while avoiding obstacles, this library handles the hard part: figuring out which route to take. The core concept is simple. You define a grid by specifying its width and height, then mark certain cells as blocked (walls, obstacles, water, whatever you want to treat as impassable). You then create a finder, give it a start coordinate and an end coordinate, and it returns a list of grid coordinates representing the path to follow. The library includes eleven different pathfinding algorithms. The most commonly known one is A Star, which finds the shortest path efficiently. Others include Dijkstra, Breadth First, Best First, and Jump Point, plus bidirectional versions of several of these. Not all algorithms are guaranteed to find the shortest possible route, the README marks which ones are. For most game use cases, A Star is the standard choice. There are also options to tune behavior: you can allow diagonal movement (by default only up, down, left, and right are allowed), prevent paths from cutting through corners of blocked cells, and swap between different distance calculation methods (Manhattan, Euclidean, Chebyshev, or Octile) depending on your game's movement rules. After finding a path, utility functions let you smooth it (removing unnecessary zigzags) or compress it down to just the key turning points. The library works both in Node.js and directly in the browser. It comes with an online visual demo showing each algorithm stepping through a grid in slow motion, which makes it easy to see the differences between algorithms at a glance. The project is MIT-licensed.

Copy-paste prompts

Prompt 1
Set up a 10x10 grid in pathfinding.js, mark some cells as walls, and find the shortest path from top-left to bottom-right using A*.
Prompt 2
How do I enable diagonal movement in pathfinding.js without cutting through wall corners?
Prompt 3
Walk me through the difference between A* and Jump Point Search in pathfinding.js, when should I use each one?
Prompt 4
How do I smooth a computed path in pathfinding.js to make character movement look less mechanical?
Prompt 5
Use pathfinding.js in a Node.js script to compute paths for a batch of start/end coordinates.
Open on GitHub → Explain another repo

← qiao on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.