6 Replies Latest reply on Apr 10, 2007 6:38 AM by dummyboo

    Flash Game: Enemy AI

      ok last question out of me (hopefully). basically i'm still doing that fighting game, got the health bar, got the damage detector or whatever you wanna call it (where only the person attacking does the damage and the other health bar goes down). i have the character select thing, the movement code, the terrain limits, the game over screen when you die, all that. i just have no idea how to make it so the enemy character does random movements (generally toward the player), randomly attacks, etc. i figured there would be some long incredibly complicated actionscript gode i'd have to use but i have no clue what it is. so can anyone help me out with that? or at least give me a link to a tutorial or something that would tell me how to do it? thanks in advance for any help.
        • 1. Re: Flash Game: Enemy AI
          kglad Adobe Community Professional & MVP
          does the enemy have to avoid obstacles or stay on a path? if not, the coding to have the enemy move towards a player and attach when within range is not complex.

          however, if there are obstacles to avoid or a path for movement, coding becomes more complex.
          • 2. Re: Flash Game: Enemy AI
            wesm9787 Level 1
            there aren't going to be any obstacles or anything, at least not yet. i might add those in later and make a version 2 of the game or something, but i doubt it. right now i just want to have a set of enemies that are selected based on which character the player selects (so he won't end up fighting himself, although if thats incredibly complicated i'll just have the person fight all 4 people, even himself).

            so i forgot about that part, if you know how to do that and how to make the guy move forward and backward and turn to face to player and try and attack him and all that i would like to know. i haven't done anything in actionscript ever until about 2 weeks ago so i'm still kinda new to this but for the most part i'm getting it pretty easily.
            • 3. Re: Flash Game: Enemy AI
              DZ-015 Level 1
              Ok. You are getting ahead of yourself. Before you worry about how to code your AI (though it's not really AI, just actions) of your characters, you need to focus a little on the model of your game.

              Take a look at the "model-view-controller" design pattern... wikipedia.org has a good introductory page on it... Once you have a good idea of how your application should flow, you can start building classes for various things (ie, a userControl class, or a enemyControl class...) and you can build your ai into where it belongs.

              If you are still asking questions like "how do i make the guy move forward and backward" then you still need to learn more actionscript. Believe me, spending some time on some tutorials will save you time in the end, and make your game a lot cooler.

              Good luck
              • 4. Re: Flash Game: Enemy AI
                wesm9787 Level 1
                i know how to make people move forward and backward, i just don't know how to add the clip of the enemy walking toward the player and when he gets to a certain point have him do attacks and stuff like that. and i've looked at tutorials but so far nothing i've found has explained that part yet, that's why i'm asking.if you know of one that explains all that could you give me a link to it?
                • 5. Flash Game: Enemy AI
                  wesm9787 Level 1
                  ok well i've looked at every tutorial i can find and none of them work... they all tell me to use an almost identical code and the only one that even somewhat worked didn't really work at all since it made the enemy just walk in a straight line in one direction off the stage. they all said i had to use something like
                  if (enemy._x<character._x){ enemy._x +=5; xscale=100} else if (enemy._x>character._x){ enemy._x -=5; xscale=-100}

                  there were some different variations but they all pretty much looked like that. and none of them did anything at all to him. except one, which like i said just made him walk off the stage and never return. so can anyone show me a site where someone actually knows what he's talking about or isn't doing it in flash 5, because i'm using flash 8 and some of the stuff they tell me to do doesn't do anything and i have to figure it out myself.

                  sorry i keep bothering you guys but nobody i know knows anything about this stuff and like i said none of the tutorials work. i copy and paste the codes exactly as they have them and i have everything named right, all the instances named, all the linkages taken care. and some of it works, some of it does nothing, and some it does something weird it's not supposed to do. and i don't know enough about this yet to figure it all out on my own.
                  • 6. Re: Flash Game: Enemy AI
                    Enemy AI is acually quite easy. Just send the .fla file to me at dummyboo@lycos.com, I'll make the AI for you and send it back.

                    click here for a small example of my AI.