Page 1 of 1

Terra A* Pathfinding

Posted: Sat Jul 02, 2016 11:15 pm
by Autophoenix
Yes, I know people have done it before, but I really wanted to create a pathfinder myself, so here it is!
It's my Lua pathfinder called Terra! :ultrahappy: (It's pronounced like Te-ha) And it's pretty easy to use, here's a tutorial:

First of all, you need to have a map and a player!

Code: Select all

MightyMap = {}
MightyMap[1] = {0, 1, 2}
MightyMap[2] = {0, 2, 0}
MightyMap[3] = {0, 3, 0}

player = {y = 1, x = 1}
Then you have to set the list of tiles you can walk, the starting position and the finish position.

Code: Select all

terra.setWalkableNodes{2, 3}
terra.setStartingNode(y, x)
terra.setTargetNode(y, x)
Now you can start pathfinding!

Code: Select all

path = terra.pathfind(MightyMap)
Getting the character to move along the path:

Code: Select all

step = 1
function love.update(dt)
        player.y, player.x = path[step].y, path[step].x
        step = step + 1
end
TODO: Add corner avoidance
If you find any bugs, please tell me :)

Re: Terra A* Pathfinding

Posted: Mon Jul 04, 2016 10:04 am
by rmcode

Code: Select all

Error: main.lua:58: bad argument #1 to 'isDown' (number expected, got string)
stack traceback:
	[C]: in function 'isDown'
	main.lua:58: in function 'update'
	[string "boot.lua"]:463: in function <[string "boot.lua"]:435>
	[C]: in function 'xpcall'

Re: Terra A* Pathfinding

Posted: Mon Jul 04, 2016 8:09 pm
by Autophoenix
rmcode wrote:

Code: Select all

Error: main.lua:58: bad argument #1 to 'isDown' (number expected, got string)
stack traceback:
	[C]: in function 'isDown'
	main.lua:58: in function 'update'
	[string "boot.lua"]:463: in function <[string "boot.lua"]:435>
	[C]: in function 'xpcall'
Sorry, I made it in Löve 0.9.2, I'm gonna make a version for 0.10.

Re: Terra A* Pathfinding

Posted: Mon Jul 04, 2016 8:32 pm
by Manyrio
http://puu.sh/pQjBY/633e4f7e57.png
Wow ! It's really great !

Re: Terra A* Pathfinding

Posted: Tue Jul 05, 2016 5:49 am
by Murii
I've looked over the demo and source code and everything seems to work fine. Good job on making this lib!
Could you provide the references used for making this pathfinding class so people who are interested in knowing how it works can make an idea?