I think I got this working for you.Jasoco wrote:I'm interested in implementing this class/library/whatever into some games. It works pretty well. But I don't like how it handles diagonal movement where it cuts corners.
Go to line 80 in Astar.lua and replace the following:
Code: Select all
local left,right = false,false
if not self.diagonalMove then -- Diagonal Moves, optional!
left = (y==self.currentNode.y-1) and ((x==self.currentNode.x-1) or (x==self.currentNode.x+1))
right = (y==self.currentNode.y+1) and ((x==self.currentNode.x-1) or (x==self.currentNode.x+1))
end
if not left and not right then
Code: Select all
local stop = false
if self.diagonalMove then -- Skip if this is a diagonal node but is blocked by an adjacent node.
local xdiff, ydiff = x - self.currentNode.x, y - self.currentNode.y
if math.abs(xdiff) == 1 and math.abs(ydiff) == 1 then
if not self:isWalkable(Node(self.currentNode.x, self.currentNode.y+ydiff)) then stop = true end
if not self:isWalkable(Node(self.currentNode.x+xdiff, self.currentNode.y)) then stop = true end
end
else -- Diagonal Moves, optional!
stop = (y==self.currentNode.y-1) and ((x==self.currentNode.x-1) or (x==self.currentNode.x+1))
stop = stop or ( (y==self.currentNode.y+1) and ((x==self.currentNode.x-1) or (x==self.currentNode.x+1)) )
end
if not stop then