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)
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!!!
Best way to do distance:
Put this inside a movielcip on the main timeline:
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!!!
Give me some ideas and ill knock up some more!!
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.
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!!!
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.
Preaty neat a ? Now I still think about a real chaser with a good collision detection.
Pardon the few bugs I havet set the coords corectrly but this is not a problem.
Cool man!!dont forget random direction,left,right,up,down and set the ditance to be about 10!!!
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.
well the distance is totally inadequate why not use the one above???5000 for such a small distance is not very good!!!
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.
You all should check out this page for more info on A* and other pathfinding methods:
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?
i've written today a little pacman-style game...
probablly i can youse your a-thing...
just have a look:
KILL THOSE MUSHROOMS!!!
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.
tell me about the regular collission detection?!?
i 've done it on my own...
perhaps it's the same solution...
KILL THOSE MUSHROOMS!!!
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.
Click Here to Expand Forum to Full Width
Poll by Flashkit.com