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.
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:
Set Variable: "/player:x" = GetProperty ("",_x )
Set Variable: "/player:y" = GetProperty ("",_y )
Begin Tell Target ("/player")
Go to and Play (5)
End Tell Target
next for the movielcip called player.
Inside this movielcip on the first frame put:
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
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)
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
and on the frame after that put:
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
Set Variable: "output" = z
this will tell the target movielcip to move to the place where the user clicks his mouse!!!
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
If (ydif < 0)
Set Variable: "ydif" = ydif * -1
Set Variable: "x2" = xdif * xdif
Set Variable: "y2" = ydif * ydif
Set Variable: "c2" = x2 + y2
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
Set Variable: "distance" = Int (n) +1
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!!!
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.
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!!!
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.
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.
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.
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.
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.