Sign in to follow this  
scMaverick

Movement in RPG

Recommended Posts

Hello, this is my doubt: I have a screen of a RPG, the char is located in a grid x*y squares where the values are 0=empty, tha char can pass trough here; 1 = can`t pass. Every square represents a portion of the screen where the character can walk. So, my problem is that I'm trying to make the char to walk from one point to another choosing the shortest path, like in Age of Empires where you select a char and click where you want it to go, but with my screen and paths system. So, how could I do it?, because I have not the minimun idea! Thank very much!

Share this post


Link to post
Share on other sites
I would recommend A* since that is the best path finding algorithm out there. Dijkstra's Algorithm is slower and only good for pre-calculating the shortest path from all nodes in the grid.

A* on Wiki:

http://en.wikipedia.org/wiki/A_star

Share this post


Link to post
Share on other sites
Quote:
Original post by Eldritch
I would recommend A* since that is the best path finding algorithm out there. Dijkstra's Algorithm is slower and only good for pre-calculating the shortest path from all nodes in the grid.


It depends. A* is really just a modification of Dijkstra's shortest path algorithm. If you need to solve some pretty straightforward paths between two nodes (like following road that only curves a bit, or avoiding a few obstacles), A* is much more efficient. If you've got something more like a maze, where you may have to go off in the opposite direction before finding your way to the destination, Dijkstra is just as good if not better.

Share this post


Link to post
Share on other sites
if your x,y grid is small enough and static, you can use disjktra when you save the map to compute all possible shortest paths and store them in a matrix the same size as your map, where each x,y entry indicates the next node you need to step to go from your position x to a desired position y.

Have fun!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this