| | |
Shortest Path Around Obstacles?
Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2008
Posts: 1
Reputation:
Solved Threads: 0
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!
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!
•
•
Join Date: Mar 2004
Posts: 802
Reputation:
Solved Threads: 40
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
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
![]() |
Other Threads in the Game Development Forum
- Previous Thread: Invitation for Sculpt 08, A Game Design contest
- Next Thread: Help request
Views: 1596 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Game Development
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamedevelopment gameprogramming gamer games gaming gauntanamo government graphics idaho in-gameadvertisement intel intellectualproperty l-systems laracroft larrabee lindenmayer live manhunt math mathematics matrix mercenaries microsoft mmorpg modded msn multicore naked news nintendo obama opengl palin physics pirate playstation politics processor projection ps3 rpg search selection software sony stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360





