Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@codepaladin
Created May 26, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codepaladin/d85a5d7f9f0244b774fd to your computer and use it in GitHub Desktop.
Save codepaladin/d85a5d7f9f0244b774fd to your computer and use it in GitHub Desktop.
-- find the path from point A to point B
function getPath()
-- create a Jumper Grid object by passing in our map table
local grid = Grid(map)
-- Creates a pathfinder object using Jump Point Search
local pather = Pathfinder(grid, 'JPS', walkable)
pather:setMode("ORTHOGONAL")
-- Calculates the path, and its length
local path = pather:getPath(startX,startY, endX,endY)
if path then
for node, count in path:nodes() do
print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment