# Plot a Course through a Grid

This topic is 2476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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~

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013596
×