# Plot a Course through a Grid

This topic is 2784 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~

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 22
• 11
• 25