Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!