Ok I have to code A* so far so good. Ideas ?
A Flash Developer Resource Site

Results 1 to 18 of 18

Thread: Ok I have to code A* so far so good. Ideas ?

  1. #1
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756

    Smile

    Ok guys I have come to a point coding the so called A star algorithm for pathfinding. Ideas.....
    First what I have done.
    1. pseudo chaser - the bad guy moves random arround the maze and tracking the distance with the player for collision detection. this is ok if you put alot of those.
    2. WayPoint patrol - the bad guy patrols between couple of points.

    both of those are not real chasers. They are good for now. I need a real one though for Bosses and very very bad guys.

    Any sugestions, strategies, some code which you can paste stuff like this. Will be a free game for education. And I ll try to include evry imaginable trick so once you figure out how every thing is done you will be reachin the state of master AS scripter. ( Im not putting myself there though cos you will learn from my mistakes )
    I cant post those examples yet havent gotten a reply from rsnail I used his animation in Pathfinding example.
    Mad_sci

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Wll heres the best way to use the A * Pathfinding method:Right create a movieclip and name it: "mouse"
    (this will be your target movielcip)

    then on the first frame of your main timeline put:

    Start Drag ("/mouse", L=10, T=10, R=390, B=390, lockcenter)
    Stop


    next create the movieclip for your paintball:
    Call this "player"


    then Inside the movielcip called mouse put a frame and inside create the graphic for your target,now you have the target graphic turn it into a button,ont he button actions put:

    On (Release)
    Set Variable: "/player:x" = GetProperty ("",_x )
    Set Variable: "/player:y" = GetProperty ("",_y )
    Begin Tell Target ("/player")
    Go to and Play (5)
    End Tell Target
    End On


    next for the movielcip called player.
    Inside this movielcip on the first frame put:

    stop


    Next frame put:

    Set Variable: "x" = Int(GetProperty ( "/mouse" , _x))
    Set Variable: "y" = Int(GetProperty ( "/mouse" , _y))
    Set Variable: "distx" = x - GetProperty ("", _x)
    Set Variable: "disty" = GetProperty ( "" , _y) - y
    Set Variable: "input" = distx*distx+disty*disty
    Call ("sqrt")
    Set Variable: "distance" = output/speed
    Set Variable: "movex" = distx/distance
    Set Variable: "movey" = disty/distance


    the frame after that put:

    If (distance <= 0)
    Go to and stop (1)
    Else
    Set Variable: "newx" = GetProperty ("" , _x) + movex
    Set Variable: "newy" = GetProperty ("", _y) - movey
    Set Property ("", X Position) = newx
    Set Property ("", Y Position) = newy
    Set Variable: "distance" = distance - 1
    End If


    and on the frame after that put:

    Call ("3")
    Go to and Play (3)

    Now label the next frame: "sqrt" and for the actions put:

    Set Variable: "z" = 1
    Set Variable: "iterations" = 20
    Set Variable: "i" = 0
    Loop While (i<iterations)
    Set Variable: "z" = z - ((z*z - input) / (2*z))
    Set Variable: "i" = i+1
    End Loop
    Set Variable: "output" = z

    this will tell the target movielcip to move to the place where the user clicks his mouse!!!

  3. #3
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Best way to do distance:

    Put this inside a movielcip on the main timeline:

    First Frame:

    Set Variable: "iterations" = 15
    Set Variable: "xdif" = Int (GetProperty ( "/player", _x ) - GetProperty ( "/enemy", _x ))
    Set Variable: "ydif" = Int (GetProperty ( "/player", _y ) - GetProperty ( "/enemy", _y ))
    If (xdif < 0)
    Set Variable: "xdif" = xdif * -1
    End If
    If (ydif < 0)
    Set Variable: "ydif" = ydif * -1
    End If
    Set Variable: "x2" = xdif * xdif
    Set Variable: "y2" = ydif * ydif
    Set Variable: "c2" = x2 + y2

    Second Frame:
    Set Variable: "n" = 1
    Set Variable: "counter" = 0
    Loop While (counter</:iterations)
    Set Variable: "n" = n - ((n*n - c2) / (2*n))
    Set Variable: "counter" = counter+1
    End Loop
    Set Variable: "distance" = Int (n) +1


  4. #4
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    What else do you want for the game???the code i have given you just needs implementing into your game.
    use the distance script for way point patrol and collision detection and use A* method for moving the characters around randomly!!!

    Give me some ideas and ill knock up some more!!

  5. #5
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hey FlashGuru was that rsnail whatever. I dont need to move my man I need to move the bad guys.Here is what I was thinking about.

    1. the bad guy checks were the player is by geting the _x and _y coordinates.
    2. the bad guy picks a direction of moving towards the player relative to players last coords.
    3. the bad guy can move in all direction till a collision with a wall happens. Then the move in this direction is disabled.
    4. the bad guy picks a direction each lets say 1s. or less.
    5. I can implment the trace route but this make the move very nasty so I wont do it.

    seccond way of doing it.
    1. at key positions in the maze Ill paste an empty MC . Each of those will have a name lets say :
    Point1 point2.. Each movie looks for the distance to the player by getting its _x and _y and sends those to the bad_guy who calculates the next point of interception.

    This will be a bit diff. for me to code though not imposible. so most probably I have to go for the firs one.
    So what are you think.
    Mad_sci

  6. #6
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Yes use the A * method:


    Get the players x and y if the distance between the enemies x and y and the players x and y is less that say 30 then follow the player by setting the target x and target y variables to be the position of the player(this way the enemies will follow the player until they collide) if the distacne is greater than 30 then choose a random x and y co-ordinate for the characters to move to,once a random x and y has been chosen check to see if collision will occur every step and if the man will collide in his next step dont move him otherwise do!!!

  7. #7
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    You know what that acutaly is preaty good idea.
    1. Move it random till the hero gets closser then chase. humm not bad not bad at all.
    An example is comming up.
    Mad_sci

  8. #8
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    http://savco.virtualave.net/fLASH/co...loodhunter.swf

    Preaty neat a ? Now I still think about a real chaser with a good collision detection.
    Mad_sci

    Pardon the few bugs I havet set the coords corectrly but this is not a problem.

  9. #9
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    Cool man!!dont forget random direction,left,right,up,down and set the ditance to be about 10!!!

  10. #10
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    FG this is acutally a distance of about 5000 he he
    It does go in all direction and chase preaty well. I think its good for a game dont you think.
    Mad_sci

  11. #11
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    well the distance is totally inadequate why not use the one above???5000 for such a small distance is not very good!!!

  12. #12
    Senior Member
    Join Date
    Jun 2000
    Posts
    435
    Hi Mad-Sic, FlashGuru, Every one. Sorry I had lots to do at work or I would have jumped in sooner.

    What the hell, is A star Method?

    General AI & Object Comments:
    In most of my projects The Objects Layer (MC in Flash) is an array or linked list, just like the rest of my map. The only difference is its detected to hosting Object Families like; monsters, towns people, inanimate-objects, whatever. I use a similar method to manage my objects as I do my map tiles, by defining its location, properties and data, in an emulated array. I use my Object Factory class whose sole purpose is the creation of families of objects that are not tied in specifically to the function that created them. “He he he Modular Programming Its Recyclable!” To the point, I like to have an “intelligence” (much like walk-ability in my collision detection) assigned to various groups of objects.

    In my code library for the game I will have lots of different AI’s (some are just variations) labeled ether with names or numbers, that basically brake down “intelligence” of objects.

    Sample Chart:
    0. nun
    1. NPC/Monster Wander aimlessly…
    2. NPC/ Monsters Afraid of Player Characters.
    3. Docile Monsters, wander aimlessly until attacked, which changes their INT to 2. or 4.
    4. Same Docile Monsters, but know it’s mad!
    5. Normal Monsters, charge at a slow pace!
    6. Stupid Monsters, charge right at you!
    7. Projectile firing monsters!
    8. Bad Ass Monster, a boss or mean enemy that will eat you for a snack.
    9. Keys & other door-opening things.
    10. Items like: Weapons, Armor, Gold and other booty…
    11. Any other object category.

    I like using this method, all I have to do is assign an INT “intelligence” to keep track of Object behaviors. Its very helpful… understand? I hope so.

  13. #13
    A* is a really popular algorithm for finding the quickest path from point A to point B in an area with obstacles. It even can take into account different types of terrain (ie. wading through a swamp vs walking on a sidewalk.) It isn't really useful in open spaces.
    It can find the quickest path, but it doesn't always find it quickly. It can be pretty cpu intensive (depending on the complexity of the map) so isn't always appropriate.
    I've just started reading about it myself. No personal experience with it yet.

    You all should check out this page for more info on A* and other pathfinding methods:
    http://www.gamasutra.com/features/19990212/sm_01.htm

  14. #14
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hi all,
    1. the shortest way to the hero is the strait line betweent the bad guy and the hero.
    There are 2 ways of getting arround an obstacle:
    1. Trace the obstecle. compare the bad guys _x and _y with those of the obstacle and chose the shortest way around. This is not very good since the AI can actualy choose the longest way relavant to the player position.
    2. I use permitions for move. the AI picks a direction relavant to the heros _x and _y coord. goes towards till it hits something then it picks a new direction towards the player. This is ok though its not very thight.

    any more ideas?

    Mad_sci

  15. #15
    Junior Member
    Join Date
    May 2000
    Posts
    16

    nice thing...

    i've written today a little pacman-style game...
    probablly i can youse your a-thing...

    just have a look:

    http://itekk.voortekk.com/pacman/index.html

    greetings from
    terr0rbyt3

    KILL THOSE MUSHROOMS!!!

  16. #16
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    Hi I saw the thing. I would sugest if you make the PM smaller. Are you using the regular collsion detection ?
    About the A* sure Ill give the code when I write it he he for now I do expriments only see how it goes. I dont have to much expirence as well so well see.....I might fail as well if not Ill post the fla.

    Mad_sci

  17. #17
    Junior Member
    Join Date
    May 2000
    Posts
    16

    huh?

    tell me about the regular collission detection?!?

    i 've done it on my own...
    perhaps it's the same solution...

    terr0rbyt3

    KILL THOSE MUSHROOMS!!!

  18. #18
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    The regular CD we call when you move the player and check for collision when it hits a wall. You knwo my_left your right and so on located in the bricks.
    Mad_sci

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


HTML5 Development Center

Poll by Flashkit.com