Shortest Path Around Obstacles?

Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 1
Reputation: Septenary is an unknown quantity at this point 
Solved Threads: 0
Septenary Septenary is offline Offline
Newbie Poster

Shortest Path Around Obstacles?

 
0
  #1
Jan 18th, 2008
Hello,

I am making a game in Adobe Flash - Actionscript 3.0. It's not the first time I've made a game, so I do have a bit of experience - but that bit is all I have, being still at high-school level computer science. So, I apologize for any newbishness in my post.

Anyway, I am having problems moving an object from one point to another, with rectangular obstacles in between. So far, my code is something like this:

1) If the object is moving towards an end point and is touching an obstacle...
2) Send two "ghost" objects clockwise and counter-clockwise around the obstacle.
3) Move the "ghosts" to the verticies of the rectangle (CW or CCW)
4) Keep moving around the rectangle until this obstacle no longer obscures the path to the end point
5) Return the shorter path around the rectangle (CW or CCW) to the object, and make the object move along this path.

For example:

http://www.NightTowers.com/private/SamplePath1.gif

Here, the object (red square) needs to get around the obstacle (black square) to the end point (green square). So, it follows the red path.

This is ok, but probably way too simple, and problems come up like this:

http://www.NightTowers.com/private/SamplePath2.gif

The second obstacle obscures the path of the ghost.

I don't like this method at all, but it was the only thing I could come up with. Creating the "ghosts" and then moving them around verticies turns out to be pretty intensive too, and, as in the final project, I plan on including much movement and graphics, I want this to be as efficient as possible.

I need a way to efficiently make the red object find this path to the green square:

http://www.NightTowers.com/private/SamplePath3.gif

Or, whatever the shortest path around the obstacles happens to be. I want the object to be able to find the shortest, "smartest" path before it actually hits the obstacle.

If I could get some help with this problem, I would greatly appreciate it!
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: Shortest Path Around Obstacles?

 
1
  #2
Jan 18th, 2008
Look at the A* (a-star) algorithm. It's commonly used for path-finding.

Here's the article that myself and a lot of others I know have used to learn A* path-finding.
http://www.policyalmanac.org/games/aStarTutorial.htm
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Game Development Forum


Views: 1596 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Game Development
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC