Results 1 to 18 of 18

Thread: Paths

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    4
    I'm writing a tile-based rpg, and I need an algorithm that finds the shortest path from one tile to another. I've been looking around for many things and all I could find was stuff written in C++ that was too complicated to read.
    The only type of tiles are either walkable or non-walkable, so there are no varying speeds or anything. I just want some simple VB code that works. It doesn't have to be the fastest or the best, as long as I can use it.
    Any help would be appreciated, thanks!

    dvadas

  2. #2
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    A* is somewhat complex but doable.

    However, if that is too complicated, you can check to see which tile you can move on that will be the closest to your target.

    For example,
    if ((Your character).x > (Target character.x))
    ' Move left
    else if ((Your character).x < (Target character.x))
    ' Move right

    if ((Your character).y > (Target character.y))
    ' Move down
    else
    ' Move up

    There are a few problems with this (hanging on walls) but other than that, it is a simple way of doing things.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  3. #3
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Darkwraith: You fancy writing a flow blown procedure to find a path like he described?? By this I mean a procedure that would find the best way to get from one tile to another avoiding walls and avoiding hanging to walls, i say this because you seem the helping type and as you said before you bring up these threads to help others that might have similar problems , hey it could be fun , what you say??

    Are you working on a project at the moment??
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  4. #4
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    I could do the algorithm, but probably not the code.

    I am working on a few projects to learn programming languages better. If it is VB, I could probably work on it, albeit it might take a few weeks (Project MagicBase is not working out to well. A respite from it would be nice.)
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  5. #5
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    MagicBase, respite You lost me??

    If by:
    If it is VB, I could probably work on it
    you mean the path finding thing, he was asking for VB he said he only found C++ soruces which were no good . if you could do the algorithm I could probably do the code.

    I'm currently working on a game and its almost finished. When I say almost finished I mean the code, I have to make the levels after that which isn't gona be easy for me considering I can't draw on a PC to save my life .
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    As luck would have it, i've been doing something very similar (tile-based shortest path finding algorythm based on the A*).

    I wrote it in VB, as my C++ isn't too hot, but i'd emagine it could easily be ported.


    I first created the A* algorythm as it stood (no modifications - just an implimentation). My Monsters ran the algorythm each time they wanted to move. I found this to be quite CPU intensive - mainly when there was no path).

    I decided to create an array, storing a direction to move in, given a source and a destination.

    This means that the monster simply looked at it's position, and it's destination, and the array would give a direction to move in (based on the best possible move).

    To fill the array i used the A* algorythm over and over again.

    This took several minutes on a small (25x25 grid) map. Although i could save the array to a file (and did), it was still too slow.

    I then decided to refine the algorythm.

    I decided to calculate all the distances from the destination (for each node). Then to get a direction from a source, it's simply the direction of a node near it (with a link to it), with the shortest distance.

    At present, my AI module is a bit cluttered. (failed attempts etc), but i'll try to sort it out if you like (add more comments etc).
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    Here's an example, but I strongly advise you write one yourself.

    BTW: I'm slowing it down with a for-loop, and the squres 'n stuff shouldn't apppear, obviously.

    Most of the unneeded code isn't tabbed, to make it easy to find.
    Attached Files Attached Files
    Don't pay attention to this signature, it's contradictory.

  8. #8
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    MagicBase. My project name for a Magic: The Gathering database.

    Well, it looks like a moot issue now unless you want me to create another A*, Electroman.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  9. #9
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    I guess your write its no a moot issue .
    What is a A* anyway, is it just the type of algorithm thats used for this??
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  10. #10
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Electroman
    I guess your write its no a moot issue .
    What is a A* anyway, is it just the type of algorithm thats used for this??
    Yes - it's a pathfinding algorythm - widely regarded as the fastest my many academics.

    http://www.gameai.com/pathfinding.html

    http://www.intrafoundation.com/pathfinder2d.asp
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  11. #11
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    You can also try (albeit sorta old)

    Real-Time Game Programming Using MS DirectX 6.0.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  12. #12
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    you're just taking the piss now arn't you Darkwraith.

    That link doesn't seem to be a link.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  13. #13
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Did he mean it to be a link?? Isn't he just saying the name of the referance to add in VB??
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  14. #14
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Originally posted by Electroman
    Did he mean it to be a link?? Isn't he just saying the name of the referance to add in VB??

    Oops! Quite possibly. Guess we'll just have to wait and see.

    If it is a reference to add, then u'm not quite sure of it's usefulness as it is so old.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  15. #15
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Its underlined, not a hyperlink.

    It's an excellent reference in RTS design, not implementation. A section of it is dedicated to A* pathing, another to differences in design of tile based maps (rectangular, isometric, and hex)

    Furhermore, it points out questions that you should ask yourself like how should economy be handled and gameplay issues.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  16. #16
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Oh hang on is it a book, I've just thort this because I can't imagine a VB reference would tell you all that and he never actually said if it was a VB reference, as in .dll)
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  17. #17
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    It is a book about RTS using DX 6.0 and C++.

    Remember that old adage: "Give a man a fish, you feed him for a day. Teach a man to fish, you feed him for a lifetime." Well, "Give a man a coded algorithm, you help him for one programming language. Have him learn the concepts behind the code, you help him for all languages."

    The code is old, but the concepts are not (especially the detailed look at A*.)
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  18. #18
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    there is a path finding tutorial on this page: http://fox.acky.net/
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width