Page 8 of 9 FirstFirst ... 6789 LastLast
Results 71 to 80 of 90

Thread: A* pathfinding example !

  1. #71

    A* pathfinding example !

    Hi guys

    I was wondering..is there a way to find a path for an object that occupies 4 or 9 blocks.
    Let's say you want to create a game with soldiers and tanks in it,
    Then you could make the tanks bigger so they only can move when there is enough space. And soldiers could benefit from the smaller holes when they have to flee. This can make a game more realistic. :razz:

    I've tried to figure out how to do this but with no result so far.

    What do you guys think about this?? is it worth implementing? How can it be implemented??

    Thanks
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #72

    A* pathfinding example !

    If you use this unit, there is a patherror when the target cannot be reached.

    So findPath, then if patherror stand still else move along path.

    Firle

  3. #73
    Legendary Member cairnswm's Avatar
    Join Date
    Nov 2002
    Location
    Randburg, South Africa
    Posts
    1,537

    A* pathfinding example !

    This code came out of a step by step tutorial I wrote previously - start at the beginning and make it grow - it is not supposed to be cut and paste.
    William Cairns
    My Games: http://www.cairnsgames.co.za (Currently very inactive)
    MyOnline Games: http://TheGameDeveloper.co.za (Currently very inactive)

  4. #74

    A* pathfinding example !

    Still one question:

    My level is a 2 dim array of byte.
    The findpath is a bit slow.

    Sometimes my monsters get stuck. I think it is because they maybe larger than 1, and the pathfinding finds a path where only size<=1 can walk.

    So how do I get it a bit faster and working with larger monsters?

    I thought perhaps I make a new 2dim array, 140x140 (or smaller?) and copy the larger one into the smaller one with keeping all obstacles, then the found way may work for larger monsters and findpath is faster?

    Is that understandable or any better ideas?

    Thanks,
    Firle

  5. #75

    A* pathfinding example !

    in the callback, your app can return proper results depending on monster's size (use smaller grid resolution where monster can fit).
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  6. #76

    A* pathfinding example !

    Hi Delfi,

    in the sample there is nothing done with the callback.

    Could you please give a short sample how to change the callback?

    And any idea why the findpath is a bit slow with a 2dim level of 0..280,0..280?

    Right now my blocktester looks like this:
    Code:
    function TForm1.blocktester&#40;X, Y, Fx, Fy&#58; integer&#41;&#58; integer;
    begin
      result&#58;= -1; // if it isnt anything else - it is wall
      if &#40;level&#91;x,y&#93;=255&#41; then result&#58;=round&#40;&#40;&#40;ABS&#40;FX-X&#41; + ABS&#40;FY - Y&#41;&#41; * 3&#41;&#41;
      else if &#40;level&#91;x,y&#93;=0&#41; or &#40;level&#91;x,y&#93;=51&#41; then result&#58;= &#40;&#40;ABS&#40;FX-X&#41; + ABS&#40;FY - Y&#41;&#41; * 3&#41;*16;
    end;
    255 is a road (walk faster), 0 is empty and 51 is grass, also walkable.

    My findpath looks like this:
    Code:
    Astar.findpath&#40;StartPoint, EndPoint, point&#40;levelb-1,levelh-1&#41;,true,true, @blocktester&#41;;
    Levelb and Levelh contain my level width/height (280)

    Is this correct?

    Thanks a lot,
    Firle

  7. #77

    A* pathfinding example !

    when getting data for array you are now checking level[x,y], to do it on lower resolution for bigger monsters, just check accompanying blocks as well.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  8. #78

    A* pathfinding example !

    Okay, so I'll just have to add that to my blocktester.
    Thanks, I'll try that

    Firle

  9. #79

    A* pathfinding example !

    I think I got it working perfect now.

    That Innominate monsters are really dangerous now, they kill all villagers then me in a short time because they don't get stuck at obstacles anymore

    Great stuff!

    Thanks a lot Delfi!!!

    Firle

  10. #80
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    A* pathfinding example !

    *gasp* You zombie sympathizer!

    :hellspawn:
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 8 of 9 FirstFirst ... 6789 LastLast

Bookmarks

Posting Permissions

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