warrior doesn't find correct path

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

warrior doesn't find correct path

Post by Luke100000 »

Simple example of my problem:
X | O
Warrior (X) wants to run to his target (O), but there is a wall in his way (|)
How I can make that the guy finds automatical his way to O, not only with 1 wall.

X|||||||||||||
......|||O ...||
|...||||.....||
|.............||
|||||||||||||

... == floor, " " doesn't work

My idea was something like WarCraft, the warriors run to the target and took the shortest way.

It have to work fast, because of 100 or more warriors.

Thanks! :awesome:
User avatar
MGinshe
Prole
Posts: 31
Joined: Sun Apr 17, 2011 3:50 am
Location: New Zealand

Re: warrior doesn't find correct path

Post by MGinshe »

you might want to look into jumper, which is a lua implementation of the A* Search Algorithm
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: warrior doesn't find correct path

Post by Roland_Yonaba »

Technically, what you need is a pathfinding algorithm. And pathfinding is a very interesting and wide topic, and there are loads of algorithms.
Typically, Astar is a good compromise. It is widely used in games and has a dozen of variants.
Depending on your world representation (which seems to be a flat grid, in your case), its size, its dynamicity and the type of path requests
you are willing to perform (single source, all pairs shortests paths, etc) some algorithms are better than others.
MGinshe wrote:you might want to look into jumper, which is a lua implementation of the A* Search Algorithm
Jumper is not just a Astar pathfinding library, it is a bit more than that. It offers a high level API to run different pathfinding algorithms. You just pick the one you want (between Astar, Dijkstra, Jump Point Search, Breadth-First Search, Deoth First Search) and use it. You can compare them easily and decide what one suits the best your needs.

Otherwise, you can also take a look at some other implementations, or try to implement Astar for yourself. It is really learningful, and as a game developer it will help to know it. The best tutorial, AFAIK, is the Great Patrick Lester's, and the best set of resources can be found on the Great Amit Patel's website.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: warrior doesn't find correct path

Post by Luke100000 »

Thanks, an A* Search Algorithm I've searched.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests