Terra A* Pathfinding

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Terra A* Pathfinding

Post 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 :)
Attachments
terra-pathfinding.love
(8.22 KiB) Downloaded 262 times
a² = b² + c²
User avatar
rmcode
Party member
Posts: 454
Joined: Tue Jul 15, 2014 12:04 pm
Location: Germany
Contact:

Re: Terra A* Pathfinding

Post 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'
User avatar
Autophoenix
Prole
Posts: 40
Joined: Thu Mar 06, 2014 4:18 pm
Location: Rio de Janeiro, Brazil

Re: Terra A* Pathfinding

Post 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.
a² = b² + c²
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Terra A* Pathfinding

Post by Manyrio »

http://puu.sh/pQjBY/633e4f7e57.png
Wow ! It's really great !
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
Murii
Party member
Posts: 216
Joined: Fri Jul 05, 2013 9:58 am
Location: Arad, Romania
Contact:

Re: Terra A* Pathfinding

Post 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?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 205 guests