Jump to content
  • Advertisement
Sign in to follow this  
Moose6912

Simple pathfinding algorithmn

This topic is 5035 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

I need help in looking for a simple pathfinding algorithmn that moves a sprite from 1 end of a chessboard to a certain square and the chessboard has no obstacles whatsoever.I've thought of using the A* algorithmn,but seems like it takes into account any obstacles which makes it more complicated and slow.So i was wondering is there a simpler algorithmn which i can use?

Share this post


Link to post
Share on other sites
Advertisement
If there are actually no obstacles, you don't need intelligent pathfinding at all. If the target is to the northeast, north, or northwest of you, go north. If the target is to the southeast, south, or southwest of you, go south. If the target is to the west, go west. If the target is to the east, go east. Bingo.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
If there are actually no obstacles, you don't need intelligent pathfinding at all. If the target is to the northeast, north, or northwest of you, go north. If the target is to the southeast, south, or southwest of you, go south. If the target is to the west, go west. If the target is to the east, go east. Bingo.


If the target is 30 degrees of you,how do you implement the math to start going 30 degrees towards the target on a 8 X 8 chessboard?

Share this post


Link to post
Share on other sites
Quote:
Original post by Moose6912
Quote:
Original post by Sneftel
If there are actually no obstacles, you don't need intelligent pathfinding at all. If the target is to the northeast, north, or northwest of you, go north. If the target is to the southeast, south, or southwest of you, go south. If the target is to the west, go west. If the target is to the east, go east. Bingo.


If the target is 30 degrees of you,how do you implement the math to start going 30 degrees towards the target on a 8 X 8 chessboard?
If you are restricted to moving from square to square, then my algorithm will do that just fine. If you can move any direction you want (including weird diagonals that take you between rather than into squares) then it's even easier; simply point yourself towards the target and go forwards.

In retrospect, I see what the confusion may be. Just to make it clear: this decision process is applied after each one-square move. That is, you decide what direction to move in, move one square in that direction, and then you repeat the process, choosing a (possibly) different direction to move in.

[Edited by - Sneftel on September 12, 2004 11:35:39 PM]

Share this post


Link to post
Share on other sites
Then you just need to modify the algorithm slightly: if the target is north, northwest, or west, go one space northwest. If it's south, southeast, or east, go one space southeast. If it's northeast, go one space northeast. If it's southwest, go one space southwest. Rinse, repeat.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

while ((TargX!=CurX) AND (TargY!=CurY))
{ // loop steps til current coords are target coords
dx = TargX-CurX;
dy = TargY-CurY;

if (dx>0) NewX=CurX+1;
else if (dx0) NewY=CurY+1;
else if (dy<0) NewY=CurY-1;
}


I used something like this more than 25 years ago for various games .

If you want a cleaner linear stepping pattern look at the basic Bresenham line-draw algorithm (do a web search)....

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Original post by Anonymous Poster

while ((TargX!=CurX) AND (TargY!=CurY))
{ // loop steps til current coords are target coords
dx = TargX-CurX;
dy = TargY-CurY;

if (dx>0) NewX=CurX+1;
else if (dx0) NewY=CurY+1;
else if (dy0) NewX=CurX+1;
else if (dx0) NewY=CurY+1;
else if (dy<0) NewY=CurY-1;
}






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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!