Hi - I'm playing around trying to learn some techniques w/ a simple game I made.
I have a character on a grid and each intersection of grid lines is identified by x,y coordinates.
To start, my character is being randomly placed on the grid. If the ground were a 10x10 grid of square tiles (top left being 0,0 and bottom right being 10,10), my goal is to have the character move to a final destination, like 10,5 (right side midway down).
It takes 2 seconds for the character to pass to the next grid point.
I'm wondering what would be a good way to decide which way the character should move to the next grid point, or plot a course (I do have grids that can't be crossed like dangerous fire pits, alligators, etc...).
It seems simple to just compare x/y coordinates and see which one is closest to the endpoint, but I was wondering if there is a "smarter" more intelligent way to go about this in "game programming".
Any help much appreciated.
Plot a Course through a Grid
Looks like what you need are Pathfinding algorithms. http://en.wikipedia.org/wiki/Pathfinding
Try Dijkstra's path finding algorithm, since (IMO) it's the easiest to begin with. A* algorithm is faster, but I'd encourage you to first get a working implementation and understanding of Dijkstra's before using A*.
Fire pits, alligators etc can be represented by MAX_INT (i.e. very large) values for edge weights.
Cheers
~dd~
Try Dijkstra's path finding algorithm, since (IMO) it's the easiest to begin with. A* algorithm is faster, but I'd encourage you to first get a working implementation and understanding of Dijkstra's before using A*.
Fire pits, alligators etc can be represented by MAX_INT (i.e. very large) values for edge weights.
Cheers
~dd~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement